How to install ruby system-wide using rbenv

前端 未结 1 2052
情书的邮戳
情书的邮戳 2021-01-16 12:39

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

How

相关标签:
1条回答
  • 2021-01-16 12:59

    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.

    0 讨论(0)
提交回复
热议问题