2013-04-04 153 views
7
[email protected]:~$ rbenv global 
1.9.3-p392 
[email protected]:~$ rbenv local 
1.9.3-p392 
[email protected]:~$ which ruby-build 
/usr/local/bin/ruby-build 
[email protected]:~$ rbenv versions 
* 1.9.3-p392 (set by /home/hyperrjas/.ruby-version) 
[email protected]:~$ rbenv version 
1.9.3-p392 (set by /home/hyperrjas/.ruby-version) 
[email protected]:~$ rbenv rehash 
[email protected]:~$ ruby -v 
-bash: ruby: command not found 
[email protected]:~$ env | grep PATH 
PATH=/home/hyperrjas/.rbenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games 
NODE_PATH=/usr/lib/nodejs:/usr/lib/node_modules:/usr/share/javascript 
[email protected]:~$ export PATH="$HOME/.rbenv/bin:$PATH" 
[email protected]:~$ ruby -v 
-bash: ruby: command not found 

我正在使用Ubuntu 12.04。-bash:ruby:command not found

這是我~/.profile文件:

# ~/.profile: executed by the command interpreter for login shells. 
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login 
# exists. 
# see /usr/share/doc/bash/examples/startup-files for examples. 
# the files are located in the bash-doc package. 

# the default umask is set in /etc/profile; for setting the umask 
# for ssh logins, install and configure the libpam-umask package. 
#umask 022 

# if running bash 
if [ -n "$BASH_VERSION" ]; then 
    # include .bashrc if it exists 
    if [ -f "$HOME/.bashrc" ]; then 
     . "$HOME/.bashrc" 
    fi 
fi 

# set PATH so it includes user's private bin if it exists 
if [ -d "$HOME/bin" ] ; then 
    PATH="$HOME/bin:$PATH" 
fi 
export PATH="$HOME/.rbenv/bin:$PATH" 
eval "$(rbenv init -)" 
eval "$(rbenv init -)" 
eval "$(rbenv init -)" 

我已經安裝了紅寶石rbenv最後一個版本,當我嘗試ruby -v我得到-bash: ruby: command not found

+0

我認爲你需要運行一個添加ruby到你的$ PATH的命令,不幸的是我不知道是什麼那個命令是,祝你好運! – OneChillDude 2013-04-04 19:17:34

+0

FWIW,你可以考慮轉向[RVM](http://rvm.io) – 2013-04-04 19:20:07

+0

RVM和rbenv同樣好。 rbenv重量更輕,並且更簡單,移動部件更少。 RVM有很多功能,還有更多的事情會出錯。 – 2013-04-04 19:23:33

回答

9

rbenv在您〜/ .bash_profile中到底需要這些:

export PATH="$HOME/.rbenv/bin:$PATH" 
eval "$(rbenv init -)" 

使用grep rbenv ~/.bash_profile,看看他們在那裏。

如果沒有,運行:

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

,你應該是啓動和運行。

有關更多信息,請參見the docs中的步驟2和3。

對.bashrc中的其他信息,以及的.bash_profile .profile文件中可以找到:

+0

'rbenv init'可以使墊片和自動完成。 – Stefan 2013-04-04 19:32:34

+0

我已經添加到質疑我的'〜/ .profile'文件。謝謝 – hyperrjas 2013-04-04 19:34:26

+0

我不明白爲什麼在rbenv文件中指定是否運行Ubuntu可能會添加** Ubuntu note **:'修改〜/ .profile而不是〜/ .bash_profile.'。如果用'〜/ .profile'不工作,爲什麼在doc中指定? – hyperrjas 2013-04-04 19:38:56

3

運行env | grep PATH,並確保你在你的PATH有$HOME/.rbenv/bin

如果不是,請將其添加到〜/ .bash_profile。

export PATH="$HOME/.rbenv/bin:$PATH" 
+0

謝謝我已經嘗試過,但是我得到了同樣的結果。這是我的'env | grep PATH PATH =/home/hyperrjas/.rbenv/bin:/ usr/local/sbin:/ usr/local/bin:/ usr/sbin:/ usr/bin:/ sbin:/ bin:/ usr/games NODE_PATH =/usr/lib/nodejs:/ usr/lib/node_modules:/ usr/share/javascript'謝謝 – hyperrjas 2013-04-04 19:19:56

+1

打開一個新的終端窗口。您的更改將應用​​於下一個終端窗口登錄。 – 2013-04-04 19:21:42