簡體   English   中英

如何確定安裝的 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_VERSIONRUBY_PATCH_LEVEL可用,因此您可以調用ruby命令並讓它給出您想要的信息。

$ /usr/bin/ruby -e 'puts RUBY_VERSION'
2.5.5

暫無
暫無

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

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