简体   繁体   English

rbenv: ruby​​: 命令未找到

[英]rbenv: ruby: command not found

I am using rbenv with ruby version 1.9.1-p378 on the local dir.我在本地目录上使用 rbenv 和 ruby​​ 版本 1.9.1-p378。

Command ruby -v gives the following error:命令ruby -v给出以下错误:

rbenv: ruby: command not found

The `ruby' command exists in these Ruby versions:
2.0.0-p353

Any clue why this happens?任何线索为什么会发生这种情况? The bundle, rails commands do not work either. bundle, rails 命令也不起作用。

Command rbenv versions :命令rbenv 版本

* 1.9.1-p378 (set by /home/user/Desktop/r1/noko1/.ruby-version)
2.0.0-p353
  1. The complaint you get comes from rbenv.您收到的投诉来自rbenv。 The fact that it's complaining shows that rbenv is set up and working.它抱怨的事实表明 rbenv 已设置并正常工作。

  2. Figure out what version of Ruby is needed to run the project.确定运行项目所需的 Ruby 版本。 Either the project comes with a .ruby-version file in the root, or someone on the project will know and recommend that version to use.项目的根目录中带有 .ruby-version 文件,或者项目中的某个人知道并推荐使用该版本。

  3. If the version is not specified in a .ruby-version file, create the .ruby-version file in the project directory.如果 .ruby-version 文件中未指定版本,请在项目目录中创建 .ruby-version 文件。

  4. type ruby -v while in that directory.在该目录中键入ruby -v Is it OK?可以吗? Then you have the version of Ruby installed that matches what your .ruby-version is asking for.然后您安装了与您的 .ruby-version 要求相匹配的 Ruby 版本。

  5. If the last command was not OK, then type rbenv install .如果最后一个命令不正确,则键入rbenv install

Now that Ruby is installed, you need to run your program.现在安装了 Ruby,您需要运行您的程序。 I'm assuming it comes with a Rakefile.我假设它带有一个 Rakefile。

  1. install the bundler tool: gem install bundler .安装捆绑工具: gem install bundler

  2. install the dependancies of the project: bundle install安装项目的依赖: bundle install

  3. run your project using the exact versions of libraries it specifies: bundle exec rails server使用它指定的库的确切版本运行您的项目: bundle exec rails server

Try the following piece of code depending on the current version of rails that you have installed.根据您安装的当前版本的 rails 尝试以下代码。 In my case am using v2.3.3就我而言,我使用的是v2.3.3

rbenv global 2.3.3

Even setting global or local doesn't work if you haven't set this如果你没有设置这个,即使设置全局或本地也不起作用

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

It seems you need to rbenv install the ruby version you want to use, since only 2.0.0-p353 is available.看来您需要rbenv install您要使用的 ruby​​ 版本,因为只有2.0.0-p353可用。 See rbenv help .请参阅rbenv help

Even there is correct answer above, but it is not clear for my first check, so give a complete answer as a summarize based on z5h and Thengugi's answer.即使上面有正确答案,但我的第一次检查还不清楚,所以根据z5h和Thengugi的答案给出一个完整的答案作为总结。 After setup and install ruby using rbenv as below (I installed 2.5.0):使用 rbenv 设置并安装 ruby​​ 后,如下所示(我安装了 2.5.0):

rbenv install 2.5.0

You also need set it as the default version in your OS (CentOS for me):您还需要将其设置为操作系统中的默认版本(对我来说是 CentOS):

rbenv global 2.5.0

请使用 rbenv global ruby​​-version 将 gem 设为全局。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM