【轉】rvm安裝ruby,gem,rails,以後仍然沒法找到rails命令

轉自:http://chinacheng.iteye.com/blog/1738036python

rvm安裝ruby和rails以後,ruby -v好使,gem -v好使。可是rails -v很差使,提示沒有安裝rails應用。 bundle -v也遇到了相同的問題。顯然是系統沒有把他加到相應的環境變量中去,手動添加環境變量多是一種方式,當時既然咱們用rvm來管理咱們的各個版本的ruby和rails,那麼這個時候咱們去手動添加環境變量顯然是不合適的。

那麼究竟是其餘的什麼緣由的,是rvm,我運行rvm use 1.9.3 --default提示我說rvm is not a function。好吧知道緣由了吧。能夠用如下命令來解決。 shell

    source ~/.rvm/scripts/rvm  
    type rvm | head -n 1  

 執行上面的命令吧,以後你會看到這個
rvm is a function

另外這個只會對當前會話有效,若是要長期有效的話,把 source ~/.rvm/scripts/rvm添加到 ~/.bashrc便可

在Multi-User模式安裝的狀況下,rvm是安裝在/usr/local/rvm/下,另外它在安裝的時候會在/etc /profile.d/目錄下產生一個rvm.sh的腳本文件,查看/etc/profile文件的代碼,就會發現,全部用戶都會加載的這個 profile文件會遍歷運行/etc/profile.d 下的全部腳本文件。
可是我按照默認的開啓終端方式,卻沒法找到rvm這個命令。su - 用戶名是能夠的,這就有點奇怪了,後來看到這篇文章 http://ruby-china.org/topics/3705 ,文章中說的偏偏是「Ubutnu的Gnome Terminal在啓動時是non-login shell,而non-login shell只會讀取~/.bashrc來進行初始化,因此沒有讀入寫在~/.bash_login中的RVM loading line,以致於RVM沒有做爲function載入,故悲劇發生了。」,其中的一個解決方式:就是設置Gnome Terminal以login的方式啓動

Gnome Terminal默認是no-login的啓動,這種狀況下的加載 ruby

    execute /etc/bash.bashrc  
    IF ~/.bashrc exists THEN  
        execute ~/.bashrc  
    END IF  

 login shell執行的是下面
bash

execute /etc/profile  
IF ~/.bash_profile exists THEN  
    execute ~/.bash_profile  
ELSE  
    IF ~/.bash_login exist THEN  
        execute ~/.bash_login  
    ELSE  
        IF ~/.profile exist THEN  
            execute ~/.profile  
        END IF  
    END IF  
END IF

 這樣就不難理解爲何默認狀況下沒法加載/etc/profile.d/下的rvm腳本了

文章二:類unix系統是如何初始化shell的
http://reyesyang.info/articles/26-how-to-initialize-a-new-shell-in-unix-like-osspa

相關文章
相關標籤/搜索