【问题标题】:-bash: ruby: command not found-bash:红宝石:找不到命令
【发布时间】:2013-03-27 00:49:48
【问题描述】:
hyperrjas@serv1:~$ rbenv global
1.9.3-p392
hyperrjas@serv1:~$ rbenv local
1.9.3-p392
hyperrjas@serv1:~$ which ruby-build
/usr/local/bin/ruby-build
hyperrjas@serv1:~$ rbenv versions
* 1.9.3-p392 (set by /home/hyperrjas/.ruby-version)
hyperrjas@serv1:~$ rbenv version
1.9.3-p392 (set by /home/hyperrjas/.ruby-version)
hyperrjas@serv1:~$ rbenv rehash
hyperrjas@serv1:~$ ruby -v
-bash: ruby: command not found
hyperrjas@serv1:~$ 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@serv1:~$ export PATH="$HOME/.rbenv/bin:$PATH"
hyperrjas@serv1:~$ ruby -v
-bash: ruby: command not found

我正在使用 ubuntu 12.04。

这是我的~/.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​​ 的最新版本,当我尝试 ruby -v 时,我得到了 -bash: ruby: command not found

【问题讨论】:

  • 我认为您需要运行一个将 ruby​​ 添加到 $PATH 的命令,不幸的是我不知道该命令是什么,祝您好运!
  • FWIW,你可以考虑转向RVM
  • RVM 和 rbenv 一样好。 rbenv 重量更轻,更简单,移动部件更少。 RVM 有很多功能,但要出错的地方也很多。

标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-3.2 rbenv


【解决方案1】:

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 的其他信息可以在以下位置找到:

【讨论】:

  • rbenv init 启用 shims 和自动补全。
  • 我不明白为什么在 rbenv 文档中指定如果您正在运行 ubuntu 可以添加 Ubuntu note:Modify your ~/.profile instead of ~/.bash_profile.。如果 ~/.profile 不起作用,为什么在文档中指定?
  • 好。我认为您会发现 rbenv 非常适合“正常”开发。我使用 RVM 很长时间了,发现它太大了,无法满足我的需求。
【解决方案2】:

运行 env | grep PATH 并确保您的 PATH 中有 $HOME/.rbenv/bin

如果不是,请将其添加到 ~/.bash_profile。

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

【讨论】:

  • 谢谢我已经尝试过了,但我得到了相同的结果。这是我的env | grep PATHPATH=/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谢谢
  • 打开一个新的终端窗口。您的更改将在下一次终端窗口登录时应用。
猜你喜欢
  • 2014-02-12
  • 2016-02-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-03
  • 2012-12-10
  • 1970-01-01
相关资源
最近更新 更多