问题
You may think this is a classic "global" command question, but it is not.
I can set ruby globally by this:
rbenv global 2.5.1
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.
I believe we should have to install or symlink to /usr/bin
or /usr/local/bin
or something...
I couldn't find anything regarding to this. How can I make selected ruby version to be seen to other applications?
My only solution is to build ruby myself to system dir but this will conflict with rbenv.
Examples:
- When postfix want to pipe an email to ruby it cannot find ruby even i set global.
- When webmin trying to run a command via ruby it cannot find ruby too.
Workaround:
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?
回答1:
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.
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.
Installing rbenv
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
Make sure the users that will use rbenv are part of the group you associated with the rbenv folder.
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 -)"
Installing ruby-build (optional)
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
Notes
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.
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.
来源:https://stackoverflow.com/questions/49554408/how-to-install-ruby-system-wide-using-rbenv