Terminal

Ruby更新無法使用兩種方法

  • September 27, 2013

我嘗試在我的 mac 10.6.8 上安裝 ruby​​ 版本 1.9.3:

$ \curl -L https://get.rvm.io | bash -s stable --ruby

Oskar-Niburskis-MacBook-Pro:~ oskarniburski$ rvm install ruby-1.9.3-p362
Searching for binary rubies, this might take some time.
No binary rubies available for: osx/10.6/i386/ruby-1.9.3-p362.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for osx.
Installing requirements for osx.
Updating system.............................................
Installing required packages: autoconf, automake, libtool, pkgconfig, libiconv, libyaml, libffi, readline, libksba, openssl, curl-ca-bundle, sqlite3, zlib, gdbm, ncurses...
Error running 'requirements_osx_port_libs_install autoconf automake libtool pkgconfig libiconv libyaml libffi readline libksba openssl curl-ca-bundle sqlite3 zlib gdbm ncurses',
please read /Users/oskarniburski/.rvm/log/1380238189_ruby-1.9.3-p362/package_install_autoconf_automake_libtool_pkgconfig_libiconv_libyaml_libffi_readline_libksba_openssl_curl-ca-bundle_sqlite3_zlib_gdbm_ncurses.log
Requirements installation failed with status: 1.

我的版本:

Oskar-Niburskis-MacBook-Pro:~ oskarniburski$ ruby --version
ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin10.0]

日誌文件的輸出:

Oskar-Niburskis-MacBook-Pro:~ oskarniburski$ cat /Users/oskarniburski/.rvm/log/1380238189_ruby-1.9.3-p362/package_install_autoconf_automake_libtool_pkgconfig_libiconv_libyaml_libffi_readline_libksba_openssl_curl-ca-bundle_sqlite3_zlib_gdbm_ncurses.log
[2013-09-26 19:30:17] requirements_osx_port_libs_install
requirements_osx_port_libs_install () 
{ 
   __rvm_try_sudo port install "$@" || { 
       typeset ret=$?;
       rvm_warn "There were package installation errors, make sure to read the log.";
       return $ret
   }
}
current path: /Users/oskarniburski
command(16): requirements_osx_port_libs_install autoconf automake libtool pkgconfig libiconv libyaml libffi readline libksba openssl curl-ca-bundle sqlite3 zlib gdbm ncurses
Warning: Xcode does not appear to be installed; most ports will likely fail to build.
--->  Computing dependencies for autoconfError: Unable to execute port: can't read "build.cmd": Failed to locate 'make' in path: '/opt/local/bin:/opt/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin' or at its MacPorts configuration time location, did you move it?
There were package installation errors, make sure to read the log.

然後嘗試使用 MacPorts 安裝,但它也沒有再次工作。有任何想法嗎?

Oskar-Niburskis-MacBook-Pro:~ oskarniburski$ sudo port install ruby19
Warning: Xcode does not appear to be installed; most ports will likely fail to build.
--->  Computing dependencies for ruby19Error: Unable to execute port: can't read "build.cmd": Failed to locate 'make' in path: '/opt/local/bin:/opt/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin' or at its MacPorts configuration time location, did you move it?

這是我現在的路徑:

/opt/local/bin:/opt/local/sbin:/usr/local/git/bin:/usr/X11/bin:/Users/oskarniburski/.rvm/bin:/usr/X11R6/bin:/Library/Frameworks/Python.framework/Versions/3.3/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/Versions/Current/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin:/Users/oskarniburski/.rvm/bin

‘which -a make’ 和 locate -b ‘\make’ 都不是。第一個沒有找到哪個命令,後者的定位:非法選項–b

問題1:make

第一個問題是 ruby​​ 需要編譯,這通常是通過make從 a 讀取設置Makefile然後呼叫編譯器來完成的。在 OSXmake上安裝了Xcode它的工具,/Developer/usr/bin而不是/usr/bin預期的位置。此目錄不在預設目錄中,$PATH因此 shell 找不到其中的任何執行檔。

您可以通過將此行添加到您的~/.bash_profile(確保export $PATH在行之前添加它)為您的使用者解決此問題:

PATH="/Developer/usr/bin:$PATH" 

sudo但是,任何以 root 身份執行的命令(例如)仍然無法訪問它。我建議您將此目錄添加到預設路徑。打開/etc/profile,找到定義路徑的行並將目錄添加到其中。我在 Linux 系統上,但它應該看起來像這樣:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

只需將目錄添加到末尾,如下所示:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/Developer/usr/bin"

如果您不想更改預設值,可以連結make到預設值中的目錄$PATH

sudo ln -s /Developer/usr/bin/make /usr/bin

您必須對其中的所有內容執行此操作,/Developer/usr/bin因此我真的建議您更改預設設置。

問題2:尋找新版本

此時您應該能夠安裝 ruby

$ sudo port install ruby19

正確退出,但您的 ruby​​ 版本似乎沒有更新:

$ ruby --version
ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin10.0]

這是因為,預設情況下port將其文件安裝在/opt/local其中並將您的 ruby​​ 執行檔安裝為/opt/local/bin/ruby1.9. 另一個不在您的$PATH. 因此,您可以重複上述過程並添加/opt/local/bin到您的$PATH,或者您可以將ruby1.9執行檔連結到您路徑中的目錄。如果你添加/opt/local/bin到你的$PATH,你將能夠執行 v1.8ruby和 v1.9 ruby1.9。如果您希望所有現有腳本都切換到 v1.9,我建議您/usr/bin/ruby指出新版本。

舊版本/usr/bin實際上是一個符號連結:

$ ls -l /usr/bin/ruby 
rwxr-xr-x 1 root wheel 76 25 Jun 2010 /usr/bin/ruby -> ../../System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby

這意味著您可以安全地刪除它並用指向新版本的連結替換它:

$ sudo rm /usr/bin/ruby; sudo ln -s  /opt/local/bin/ruby1.9  /usr/bin/ruby

如果您想恢復並ruby執行 v1.8,只需執行反向命令:

$ sudo rm /usr/bin/ruby; sudo ln -s  /System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby  /usr/bin/ruby

如果一切順利,您ruby現在的預設值為 v1.9:

$ ruby --version
ruby 1.9.3p448 (2013-06-27 revision 41675) [x86_64-darwin10]

引用自:https://unix.stackexchange.com/questions/92580