Ubuntu Server 16.04.6 LTS
Appache2 + Passenger
RVM 1.29.9(Multi-User)→rbenv(System Wide)
Ruby 2.6.3
Rails 5.2.3
本番環境なので止めるのは気がかりですが切り捨てます!!
RVMの削除 切腹メ
$ rvm seppuku Warning! PATH is not properly set up, /usr/local/rvm/gems/ruby-2.6.3/bin is not at first place. Usually this is caused by shell initialization files. Search for PATH=... entries. You can also re-add RVM to your profile by running: rvm get stable --auto-dotfiles To fix it temporarily in this shell session run: rvm use ruby-2.6.3 To ignore this error add rvm_silence_path_mismatch_check_flag=1 to your ~/.rvmrc file. Are you SURE you wish for rvm to implode? This will recursively remove /usr/local/rvm and other rvm traces? yes
yesと入力します!(斬り捨て御免メ)
Removing rvm-shipped binaries (rvm-prompt, rvm, rvm-sudo rvm-shell and rvm-auto-ruby) Removing rvm wrappers in /usr/local/rvm/bin Hai! Removing /usr/local/rvm rm: '/etc/profile.d/rvm.sh' を削除できません: 許可がありません Could not remove '/etc/profile.d/rvm.sh', please try removing it manually. rm: '/usr/local/rvm/scripts/extras/completion.zsh/_rvm' を削除できません: 許可がありません rm: '/usr/local/rvm/scripts/zsh/Completion/_rvm' を削除できません: 許可がありません Could not remove '/usr/local/rvm/', please try removing it manually. Failed to completely remove /usr/local/rvm -- You will have to do so manually. Note you may need to manually remove /etc/rvmrc and ~/.rvmrc if they exist still. Please check all .bashrc .bash_profile .profile and .zshrc for RVM source lines and delete or comment out if this was a Per-User installation. Also make sure to remove `rvm` group if this was a system installation. Finally it might help to relogin / restart if you want to have fresh environment (like for installing RVM again).
消せなかったファイルを削除
$ sudo rm /etc/profile.d/rvm.sh $ sudo rm -r /usr/local/rvm $ sudo rm /etc/rvmrc
.bashrcにパスの記述が残っていれば削除する
export PATH="$PATH:$HOME/.rvm/bin"
マルチユーザーインストールしたときに作成したrvmグループを削除
$ sudo groupdel rvm
.ruby-versionに移行済みの場合はそのまま使用
.rvmrcが残っている場合は削除
rbenvのインストール
$ sudo git clone git://github.com/sstephenson/rbenv.git /usr/local/rbenv
ruby-buildのインストール
$ sudo git clone git://github.com/sstephenson/ruby-build.git /usr/local/rbenv/plugins/ruby-build
visudo コマンドで編集
$ sudo visudo
Defaults secure_pathの変更
Defaults env_keepの追加
Defaults secure_path ="/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/rbenv/bin:/usr/local/rbenv/shims" Defaults env_keep +="RBENV_ROOT"
Rubyに必要なパッケージをインストール
# Ubuntu16.04の場合(libncurses3-dev) $ sudo apt-get install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev # Ubuntu18.04の場合(libncurses5-dev) $ sudo apt-get install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm5 libgdbm-dev
参考:
Home · rbenv/ruby-build Wiki · GitHub
rbenv使用準備
$ sudo rbenv init - export PATH="/home/[username]/.rbenv/shims:${PATH}" export RBENV_SHELL=sudo command rbenv rehash 2>/dev/null rbenv() { local command command="${1:-}" if [ "$#" -gt 0 ]; then shift fi case "$command" in rehash|shell) eval "$(rbenv "sh-$command" "$@")";; *) command rbenv "$command" "$@";; esac }
/etc/profileの一番下に下記の設定を追記
$ sudo vim /etc/profile export RBENV_ROOT=/usr/local/rbenv export PATH="$RBENV_ROOT/bin:$PATH" eval "$(rbenv init -)"
ここで一旦ログアウトするか下記コマンドを実行
$ source /etc/profile mkdir: ディレクトリ `/usr/local/rbenv/shims' を作成できません: 許可がありません mkdir: ディレクトリ `/usr/local/rbenv/versions' を作成できません: 許可がありません
Rubyバージョンの確認
$ rbenv install --list
Rubyのインストール(sudo)
$ sudo rbenv install 2.6.3
rbenvの再読込(sudo)
$ sudo rbenv rehash
デフォルトの設定
$ sudo rbenv global 2.6.3
ここでまた一旦ログアウトするか下記コマンドを実行
$ source /etc/profile
確認
$ ruby -v ruby 2.6.3p62 (2019-04-16 revision 67580) [i686-linux]
bundlerのインストール(sudo)
$ sudo gem install bundler
railsプロジェクト内に移動
bundle installの実行( --path vendor/bundleつける)
$ cd /var/www/rails $ bundle install --path vendor/bundle
パッセンジャーのインストール(sudo)
$ sudo gem install passenger
モジュールのインストール(sudo)しばらくかかります
$ sudo passenger-install-apache2-module
warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
↑これ何?(まぁ死にやしないべ)
ここにもあるよと言われ…
Besides this Passenger installation, the following other
Passenger installations have also been detected:
/usr/local/rbenv/shims/passenger
LoadModule書いてと言われ…
You did not specify 'LoadModule passenger_module' in any of your Apache
configuration files. Please paste the configuration snippet that this
installer printed earlier, into one of your Apache configuration files, such
as /etc/apache2/apache2.conf
LoadModuleを再度確認
$ passenger-install-apache2-module --snippet LoadModule passenger_module /usr/local/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/passenger-6.0.2/buildout/apache2/mod_passenger.so <IfModule mod_passenger.c> PassengerRoot /usr/local/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/passenger-6.0.2 PassengerDefaultRuby /usr/local/rbenv/versions/2.6.3/bin/ruby </IfModule>
Apache.confに確認した内容を追記(RVMのときの記述を削除して今回確認した内容に書き換え)
$ sudo vim /etc/apache2/apache2.conf LoadModule passenger_module /usr/local/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/passenger-6.0.2/buildout/apache2/mod_passenger.so <IfModule mod_passenger.c> PassengerRoot /usr/local/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/passenger-6.0.2 PassengerDefaultRuby /usr/local/rbenv/versions/2.6.3/bin/ruby </IfModule>
Apaheの再起動
$ sudo service apache2 restart
できました!
ありがとうございました
参考:
komiyak.hatenablog.jp