so I have my rails project hosted with AWS EC2 using the amazon linux server. by default, ruby -v
returns ruby 2.0 but my project was designed on 2.3.3 (latest at the time). in order for me to change the ruby version using rbenv
i have to run the following every time i log in via ssh
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
$ ~/.rbenv/bin/rbenv init
$ source ~/.bash_profile
$ eval "$(rbenv init -)"
$ type rbenv
since i have the global ruby version in rbenv set as 2.3.3 already. then i can run
$ ruby -v
#returns 2.3.3
$ rails s
#or any other rails commands
is there any way I can set it so I don't have to edit the .bash_profile every time?
what I get if I run the above code, then exit the ssh, and ssh back in
$ ruby -v
ruby 2.0.0p648 (2015-12-16) [x86_64-linux]
$ rbenv global
2.3.3
$ rbenv local
2.3.3
$ rails s
-bash: rails: command not found
##### run above code and nothing else #####
$ ruby -v
ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-linux]
$ rails s
# starts rails server without issue
It should work without your ritual after every log in. I believe you don't quite understand what's going on there. Let's start it line by line.
Once you completed it, you don't need to do it on the next logins, because it should be run automatically. If this doesn't work you could try to replace
.bash_profile
to.bashrc
in the commands above.In order to fix the version of ruby use this reference