如何使用 rbenv 在系统范围内安装 ruby [英] How to install ruby system-wide using rbenv

查看:34
本文介绍了如何使用 rbenv 在系统范围内安装 ruby的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可能认为这是一个经典的全局"命令问题,但事实并非如此.

You may think this is a classic "global" command question, but it is not.

我可以通过以下方式全局设置 ruby​​:

I can set ruby globally by this:

rbenv global 2.5.1

然而,这使得 ruby​​2.5.1 对所有用户是全局的,而不是对整个系统.当同一服务器中的应用程序想要调用 ruby​​ 或访问/管道 ruby​​ 时,它们会收到 command not found 错误.

However this makes ruby2.5.1 global for all users but not for the whole system. When an application in same server want to call ruby or access/pipe ruby, they get command not found error.

我认为我们应该安装或符号链接到 /usr/bin/usr/local/bin 或其他东西...

I believe we should have to install or symlink to /usr/bin or /usr/local/bin or something...

我找不到与此相关的任何信息.如何让其他应用程序看到选定的 ruby​​ 版本?

I couldn't find anything regarding to this. How can I make selected ruby version to be seen to other applications?

我唯一的解决方案是自己构建 ruby​​ 到系统目录,但这会与 rbenv 冲突.

My only solution is to build ruby myself to system dir but this will conflict with rbenv.

示例:

  • 当 postfix 想要通过管道将电子邮件发送到 ruby​​ 时,即使我设置为全局,它也找不到 ruby​​.
  • 当 webmin 尝试通过 ruby​​ 运行命令时,它也找不到 ruby​​.

解决方法:

在执行的脚本中将 /root/.rbenv/shims 文件夹添加到 $PATH 可以正常工作,但在某些情况下无法直接修改 $PATH.我有什么选择?

Adding /root/.rbenv/shims folder to the $PATH on executed script works as expected but in some cases it is not possible to directly modify $PATH. What is my option here?

推荐答案

rbenv 根本就不是为了支持这个而设计的,你可以在这个 Github 问题.如果您这样做,有许多技术考虑因素需要考虑,例如权限.我发现了另一篇概述该过程的博客文章 - 使用 rbenv 进行系统范围安装.打算将其复制到此答案中,以防博客文章消失.

rbenv is simply not designed to do support this, you can see the discussion surrounding this within this Github Issue. There are many technical considerations to take into account like permissions if you do this. I found another blog post outlining the process - System Wide Install With rbenv. Going to copy it into this answer incase the blog post goes away.

但是,从长远来看,您可能会发现创建或使用 Ruby 包更简单,例如 BrightBox PPA 的.

However, in the long run, you may find that it's simply easier to create or use Ruby packages, such as the BrightBox PPA ones.

安装rbenv

对于单次安装,我们将使用 ~/.rbenv 的通常位置,而不是安装到 /usr/local.如果你可以使用不同的路径想要,但这是我更喜欢的.

Instead of the usual location of ~/.rbenv for single installs we'll be installing to /usr/local. You can use a different path if you want, but this is what I prefer.

cd /usr/local
git clone git://github.com/sstephenson/rbenv.git rbenv
chgrp -R staff rbenv
chmod -R g+rwxXs rbenv

确保将使用 rbenv 的用户是您所在组的一部分与 rbenv 文件夹相关联.

Make sure the users that will use rbenv are part of the group you associated with the rbenv folder.

现在我们要在每个用户~/.profile中加入如下代码,~/.bash_profile~/.zshenv 取决于环境.你也可以在 /etc/skel/.profile/etc/skel/.bash_profile 中添加创建新用户时复制的模板文件.

Now we want to add the following code into each users ~/.profile, ~/.bash_profile, or ~/.zshenv depending on the environment. You can also add it in /etc/skel/.profile or /etc/skel/.bash_profile template files that are copied when new users are created.

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

安装 ruby​​-build(可选)

可选地,您可以安装 ruby​​-build 插件来拯救自己从自己构建.

Optionally, you can install the ruby-build plugin to save yourself from building it yourself.

cd /usr/local/rbenv
mkdir plugins
cd plugins
git clone git://github.com/sstephenson/ruby-build.git
chgrp -R staff ruby-build
chmod -R g+rwxs ruby-build

注意事项

现在你应该有 rbenv 和可选的 ruby​​-build 设置,这样你就可以开始安装和使用 Ruby.此安装与单用户安装有两个例外.全局设置适用于所有用户和单用户 rbenv 安装都可以覆盖"系统广泛安装.

Now you should have rbenv and optionally ruby-build setup so you can get started installing and using Ruby. This install is the same as the single user install with two exceptions. The global setting applies to all users and single user rbenv installs can "override" the system wide install.

如果您有权限问题,请确保 rbenv 中的所有文件文件夹属于正确的组并且用户尝试使用rbenv 也是该组的成员.

If you have permission issues make sure all the files in the rbenv folder belong to the proper group and that the users trying to use rbenv are also members of the group.

这篇关于如何使用 rbenv 在系统范围内安装 ruby的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆