-bash: ruby​​: 命令未找到

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15819800/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 21:45:21  来源:igfitidea点击:

-bash: ruby: command not found

ruby-on-railsrubyruby-on-rails-3ruby-on-rails-3.2rbenv

提问by hyperrjas

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

I'm working with ubuntu 12.04.

我正在使用 ubuntu 12.04。

This is my ~/.profilefile:

这是我的~/.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 -)"

I have installed ruby last version with rbenv and when I try ruby -vI get -bash: ruby: command not found

我已经用 rbenv 安装了 ruby​​ 最后一个版本,当我尝试时,ruby -v我得到了-bash: ruby: command not found

回答by the Tin Man

rbenv needs these at the end of your ~/.bash_profile:

rbenv 在你的~/.bash_profile末尾需要这些:

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

Use grep rbenv ~/.bash_profileto see if they're there.

使用grep rbenv ~/.bash_profile,看他们是否在那里。

If not, run:

如果没有,请运行:

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

and you should be up and running.

你应该启动并运行。

See steps 2 and 3 in the docsfor more information.

有关更多信息,请参阅文档中的2 步和第 3 步。

Additional information on .bashrc, .bash_profile and .profile can be found in:

有关 .bashrc、.bash_profile 和 .profile 的其他信息可以在以下位置找到:

回答by Frambot

Run env | grep PATHand make sure that you have $HOME/.rbenv/binin your PATH.

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

If it is not, add this to ~/.bash_profile.

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

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