簡體   English   中英

登錄時AWS EC2默認Ruby版本

[英]AWS EC2 Default Ruby Version on Login

因此,我將使用Amazon Linux服務器將AWS Project 2托管在Rails項目中。 默認情況下, ruby -v返回ruby 2.0,但是我的項目是在2.3.3上設計的(當時是最新的)。 為了讓我使用rbenv更改ruby版本,我每次通過ssh登錄時都必須運行以下命令

$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
$ ~/.rbenv/bin/rbenv init
$ source ~/.bash_profile
$ eval "$(rbenv init -)"
$ type rbenv

因為我已經在rbenv中將全球紅寶石版本設置為2.3.3。 然后我可以跑步

$ ruby -v
#returns 2.3.3
$ rails s
#or any other rails commands

有什么方法可以設置它,所以我不必每次都編輯.bash_profile?

如果運行上面的代碼,得到的是什么,然后退出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

每次登錄后,它都無需遵循您的習慣即可工作。我相信您不太了解那里發生了什么。 讓我們逐行開始。

# 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

完成后,您無需在下一次登錄時進行操作,因為它應自動運行。 如果這不起作用,您可以嘗試在上述命令中將.bash_profile替換為.bashrc

為了修復紅寶石的版本,請使用此參考

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM