简体   繁体   English

登录时AWS EC2默认Ruby版本

[英]AWS EC2 Default Ruby Version on Login

so I have my rails project hosted with AWS EC2 using the amazon linux server. 因此,我将使用Amazon Linux服务器将AWS Project 2托管在Rails项目中。 by default, ruby -v returns ruby 2.0 but my project was designed on 2.3.3 (latest at the time). 默认情况下, ruby -v返回ruby 2.0,但是我的项目是在2.3.3上设计的(当时是最新的)。 in order for me to change the ruby version using rbenv i have to run the following every time i log in via ssh 为了让我使用rbenv更改ruby版本,我每次通过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. 因为我已经在rbenv中将全球红宝石版本设置为2.3.3。 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? 有什么方法可以设置它,所以我不必每次都编辑.bash_profile?

what I get if I run the above code, then exit the ssh, and ssh back in 如果运行上面的代码,得到的是什么,然后退出ssh,然后将ssh返回

$ 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. 让我们逐行开始。

# add init of rbenv on every login to the file .bash_profile to make available rbenv CLI
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
# call rbenv native initializer for first time only (it shows you what else you could do for rbenv)
$ ~/.rbenv/bin/rbenv init
# read and execute .bash_profile (string in echo in the first cmd)
$ source ~/.bash_profile
# as far I remember it isn't used anymore
$ eval "$(rbenv init -)"
# this is just a smoke test to check if rbenv works 
$ type rbenv

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. 如果这不起作用,您可以尝试在上述命令中将.bash_profile替换为.bashrc

In order to fix the version of ruby use this reference 为了修复红宝石的版本,请使用此参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM