其他用户没有看到 Ruby 安装了 rbenv

Other user doesn't see Ruby installed with rbenv

我已经使用 rbenv 在我的 Ubuntu 14.04 服务器上安装了 Ruby root 帐户。

root@droplet:~# ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [i686-linux]

但是如果我以另一个用户身份登录,我会在执行同一命令后收到此消息:

The program 'ruby' can be found in the following packages:
 * ruby
 * ruby1.8

为什么其他用户看不到 Ruby 安装?我该如何解决?

我完全是新手,我可能错过了一些重要的东西。如果您希望我提供有关此事的任何其他信息,请告诉我。

我使用 rvm 而不是 rbenv,所以我不熟悉 rbenv。但是,我从自述文件 (https://github.com/rbenv/rbenv#locating-the-ruby-installation) 中知道,与 rvm 一样,它使用 shell 来管理各种红宝石。

查看该自述文件的 "Basic GitHub Checkout" 部分。您可以通过执行步骤 2 到 4 使其在其他用户上运行:

Add ~/.rbenv/bin to your $PATH for access to the rbenv command-line utility.

$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile

Ubuntu Desktop note: Modify your ~/.bashrc instead of ~/.bash_profile.

Zsh note: Modify your ~/.zshrc file instead of ~/.bash_profile.

Run ~/.rbenv/bin/rbenv init for shell-specific instructions on how to initialize rbenv to enable shims and autocompletion.

Restart your shell so that PATH changes take effect. (Opening a new terminal tab will usually do it.) Now check if rbenv was set up:

$ type rbenv
#=> "rbenv is a function"

要使用 rbenv 安装 Ruby 以便一台机器上的所有用户都可以使用它,您需要

  • 在 public 位置安装 rbenv,例如/usr/local/rbenv
  • 在 shell 启动文件中为每个用户设置 rbenv,例如/etc/profile:

    export RBENV_ROOT=/usr/local/rbenv
    export PATH="$RBENV_ROOT/bin:$PATH"
    eval "$(rbenv init -)"
    

A blog post by Blake Williams gives details.