Eric Guo's

Hoping writing JS, Ruby & Rails and Go article, but fallback to DevOps note

Rbenv and CentOS Ruby on Rails Production Environment Install Log


Original refer, install on a Aliyun server.

Install software in root account

Update system

Run as root:

yum update
yum install -y htop git git-lfs zlib zlib-devel gcc-c++ patch readline readline-devel libyaml-devel libffi-devel openssl-devel make bzip2 autoconf automake libtool bison curl sqlite-devel

Setup a user account

adduser deployer
gpasswd -a deployer wheel
visudo # add deployer ALL=(ALL) NOPASSWD: ALL at end
sudo su - deployer
mkdir .ssh
chmod 700 .ssh

Also disable root login and password via PermitRootLogin in /etc/ssh/sshd_config

Before exis, make sure you can login via ssh deployer@ip_address, other wise, check file permission.

Install rbenv and ruby-build

cd # as a deployer
git clone git:// .rbenv
cd ~/.rbenv && src/configure && make -C src
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
~/.rbenv/bin/rbenv init
# As an rbenv plugin
mkdir -p "$(rbenv root)"/plugins
git clone "$(rbenv root)"/plugins/ruby-build
git clone "$(rbenv root)"/plugins/rbenv-china-mirror

Install Ruby 2.6.5

rbenv install -l
rbenv install 2.6.5
rbenv global 2.6.5
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
echo "gem: --no-document" > ~/.gemrc
gem install bundler

Install Javascript Runtime

Run as root:

curl -sL | bash -
sudo yum install nodejs
curl -sL | sudo tee /etc/yum.repos.d/yarn.repo
sudo yum install yarn

Install postgresql

sudo yum install postgresql-server postgresql-contrib postgresql-devel
sudo postgresql-setup initdb
sudo systemctl start postgresql
sudo chkconfig postgresql on
sudo su - postgres
createuser deployer --pwprompt
CREATE DATABASE harman_vendor_production WITH ENCODING='UTF8' OWNER=deployer
# "local" is for Unix domain socket connections only
local all all peer
psql -d harman_vendor_production

Install nginx

sudo yum install epel-release
sudo yum install nginx

Fix permission for CentOS

sudo mkdir /var/www
cd /var/www
sudo mkdir jbl_product
sudo chown deployer:deployer jbl_product/

or further read nginx permission denied