0

I followed this guide to deploy my rails app: https://gorails.com/deploy/ubuntu/20.04#ruby Everything works fine except i would like to use rails console on the server i deployed my app, and i can't because of this message :

Your Ruby version is 2.7.0, but your Gemfile specified 3.0.0

If i ruby -v with my deploy user, here is the answer ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux

But if i sudo ruby -v, here is the answer ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-linux-gnu]. So i guess, that's where it comes from (as said in Your Ruby version is 2.7.0, but your Gemfile specified 2.7.1)...

Has anyone an idea of how i could do ?

Edit : here is my deployment script, as deploy user

git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
git clone https://github.com/rbenv/rbenv-vars.git ~/.rbenv/plugins/rbenv-vars
exec $SHELL
rbenv install 3.0.0
rbenv global 3.0.0
gem install bundler
Geo
  • 61
  • 6
  • What does `gem env` say? – tadman Jan 20 '21 at 21:30
  • 1
    If you're using RVM or rbenv then it's possible that your root user is not properly engaging that variant. RVM has `rvmsudo` specifically for this purpose. – tadman Jan 20 '21 at 21:31
  • @tadman :`RubyGems Environment: - RUBYGEMS VERSION: 3.2.3 - RUBY VERSION: 3.0.0 (2020-12-25 patchlevel 0) [x86_64-linux]` – Geo Jan 20 '21 at 21:32
  • i am using rbenv – Geo Jan 20 '21 at 21:32
  • `sudo` does load an entirely different shell which can drop your local Ruby version settings. You shouldn't deploy as `root`, and `sudo` shouldn't be a factor. You can always `bundle install --path=.bundle` to avoid having to `sudo` at all. – tadman Jan 20 '21 at 21:33
  • i don't deploy as root – Geo Jan 20 '21 at 21:35
  • Are you saying `rails c` on the deployment target causes this error but when you run `ruby -v` in the exact same location you get `3.0.0`? e.g. `ssh deployment_user@deployment_target; cd path/to/rails/app; ruby -v # 3.0.0; rails c #ERROR` ? – engineersmnky Jan 20 '21 at 21:44
  • @engineersmnky : exactly :-( – Geo Jan 20 '21 at 21:48

1 Answers1

0

Run this command

Add rbenv to bash so that it loads every time you open a terminal

echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile

source ~/.bash_profile

this will solve your problem Reference