![](/img/trans.png)
[英]How to upgrade Ruby version when I can't figure out which program was used to install Ruby?
[英]How can I figure out the installed ruby version?
在運行腳本之前,我需要測試正確的 Ruby 版本。 在項目中,我們有具有所需版本數量的 file.ruby_version。 例如.ruby_version 文件有:
2.5.5
我可以使用ruby --version
在用戶中獲取 Ruby 的當前用戶版本,但此命令返回我需要的更多信息。 例如:
ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-darwin19]
所以我的檢查不起作用:
required_ruby=$(cat .ruby-version)
current_ruby=`ruby --version`
if [ "$required_ruby" != "$current_ruby" ]; then
echo "This project uses Ruby version $required_ruby, try to checkout or install it"
fi
知道如何解決嗎?
Ruby 解釋器中有兩個特殊常量RUBY_VERSION
和RUBY_PATCH_LEVEL
可用,因此您可以調用ruby
命令並讓它給出您想要的信息。
$ /usr/bin/ruby -e 'puts RUBY_VERSION'
2.5.5
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.