命令“rbenv install”丢失。

163
在Ubuntu 10.04中,我刚刚安装了rbenv。 安装命令不存在。
rbenv 0.4.0-49-g8b04303
Usage: rbenv <command> [<args>]

Some useful rbenv commands are:
   commands    List all available rbenv commands
   local       Set or show the local application-specific Ruby version
   global      Set or show the global Ruby version
   shell       Set or show the shell-specific Ruby version
   rehash      Rehash rbenv shims (run this after installing executables)
   version     Show the current Ruby version and its origin
   versions    List all Ruby versions available to rbenv
   which       Display the full path to an executable
   whence      List all Ruby versions that contain the given executable

See `rbenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/sstephenson/rbenv#readme

我错过了什么?

10个回答

296
"

install 命令没有包含在 rbenv 中,它来自于 ruby-build 插件。您可以使用以下命令进行安装:

"
git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build

在Mac OS X上,您可以通过homebrew安装它:
brew install ruby-build

Debian(版本>= 7)和Ubuntu(版本>= 12.10)上,rbenv和ruby-build都可以使用apt-get(或aptitude)安装:

sudo apt-get update
sudo apt-get install rbenv ruby-build

在FreeBSD上,ruby-build可以在Ports Collection中获得,可以作为二进制软件包安装,也可以从端口构建:
# Using pkgng rbenv will be installed
pkg install ruby-build

# Building ruby-build form Ports will install rbenv only if the RBENV option is set
cd /usr/ports/devel/ruby-build
make install

44
ruby-build 不应该成为 rbenv 的依赖吗? - Jason
对于OpenSUSE,这个仓库有rbenv:http://download.opensuse.org/repositories/devel:/languages:/ruby:/extensions。 - Artem Russakovskii
对于Mac用户,这个命令可以解决问题:brew install ruby-build。 - Astm
1
是的,在Ubuntu 20.04上完全相同的问题 - 这个方法解决了问题。谢谢。 - mutantkeyboard

25

我发现如果从全局目录使用rbenv,必须导出RBENV_ROOT变量,否则插件将无法加载。

export RBENV_ROOT="/usr/local/rbenv"
if [ -d "${RBENV_ROOT}" ]; then
  export PATH="${RBENV_ROOT}/bin:${PATH}"
fi

4
这应该是最好的答案。 - tread
1
这是我记得的安装后设置说明的一部分。 - professormeowingtons
1
它可以工作!它也在维基上提到了:https://github.com/sstephenson/rbenv/wiki/Plugins - Lucio

14

如大家所提到的问题是缺少ruby-build。对于较旧版本的操作系统,ruby-build可能不可用作为一个apt包。在这种情况下,请使用原始说明进行安装,该说明应省略此处的单词Optional:

  1. (可选) 安装 ruby-build,它提供了 rbenv install 命令,可以简化安装新 Ruby 版本的过程。
git clone git@github.com:rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
# OR use http
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build

10

在Ubuntu上简单安装ruby-build:

sudo apt-get install ruby-build

并添加

eval "$(rbenv init -)"

加入到你的~/.bashrc文件中


6

之前我安装了ruby-build插件,并使用以下命令安装了Ruby 1.9.3-p327:

$ rbenv install 1.9.3-p327

几天后,我尝试使用以下命令安装 Ruby 2.0.0-p247:

$ rbenv install 2.0.0-p247

但是我收到了错误信息。
rbenv: no such command 'install'

我只需要运行就可以了。

$ exec $SHELL -l

这解决了问题。


对于未来阅读此内容的所有人 - 我建议使用 source 而不是 exec $SHELL,除非您知道自己在做什么:http://stackoverflow.com/questions/33048024/exec-shell-executes-from-ssh-wont-execute-in-playbook http://unix.stackexchange.com/questions/91095/what-does-exec-shell-l-do - Andreas Storvik Strauman

6

2021年回答:

如果你得到了这个错误消息,很有可能你意外地跳过了其中一条安装指令:

git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL

.bashrc 替换为您使用的任何 shell,例如 .zshrc,或手动访问您的 shell 配置文件并粘贴此行:
export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"

我强烈反对通过brewapt-get重新安装/安装Ruby来解决此问题。使用rbenv的整个目的是在将来进行ruby版本升级或在需要不同版本ruby的不同rails项目上工作时使您的生活更轻松。


5

看起来 ruby-build 没有安装。运行以下命令:

git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build

3

如果您在OSX上遇到此问题并已经通过homebrew安装了ruby-build(像我一样),则可以通过升级ruby-build来解决此问题:

brew update
brew upgrade ruby-build

这对我解决问题很有帮助。

1
当在Linux上进行独立安装ruby-build时,如果在路径中找不到可执行文件ruby-build,也会出现此问题。如果在/usr/local下安装,请尝试以下方法:
PATH=/usr/local/bin:$PATH /usr/local/bin/rbenv install ...

0
我提供了一个解决方案,但是我正在寻找一个使用MacPorts的macOS解决方案。
因此,这里是使用MacPorts的相同命令:
➜ ~ sudo port install ruby-build
Password:
--->  Computing dependencies for ruby-build
--->  Fetching archive for ruby-build
--->  Attempting to fetch ruby-build-20210804_0.darwin_19.noarch.tbz2 from https://packages.macports.org/ruby-build
--->  Attempting to fetch ruby-build-20210804_0.darwin_19.noarch.tbz2.rmd160 from https://packages.macports.org/ruby-build
--->  Installing ruby-build @20210804_0
--->  Activating ruby-build @20210804_0
--->  Cleaning ruby-build
--->  Scanning binaries for linking errors
--->  No broken files found.
--->  No broken ports found.

➜ ~ curl -fsSL https://github.com/rbenv/rbenv-installer/raw/main/bin/rbenv-doctor | bash

Checking for `rbenv' in PATH: /opt/local/bin/rbenv
Checking for rbenv shims in PATH: OK
Checking `rbenv install' support: /opt/local/bin/rbenv-install (ruby-build 20210804)
Counting installed Ruby versions: none
  There aren't any Ruby versions installed under `/Users/user/.rbenv/versions'.
  You can install Ruby versions like so: rbenv install 3.0.2
Checking RubyGems settings: OK
Auditing installed plugins: OK
➜ ~ rbenv install 3.0.2
Downloading openssl-1.1.1k.tar.gz...
-> https://dqw8nmjcqpjn7.cloudfront.net/892a0875b9872acd04a9fde79b1f943075d5ea162415de3047c327df33fbaee5
Installing openssl-1.1.1k...

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接