Making ruby available to all users

29,378

Solution 1

Don't dismiss RVM's value

You can use the repository version of Ruby but I would recommend going another way and using RVM to manage Ruby. I realize it might seem like it's slowing you down, but the version of Ruby that's deployed via the repositories though usable will often lead to problems down the road. It's generally best to create dedicated versions of interpreters and any required libraries (Gems) that can be dedicated to a particular application and/or use case.

RVM provides the ability to install for single user (which is what you did) as well as do a multi-user installation.

$ curl -L https://get.rvm.io | sudo bash -s stable

Running the installation this way will automatically trigger RVM to do a multi-user installation which will install the software under /usr/local/rvm. From here the software can be accessed by anyone that's in the Unix group rvm.

$ sudo usermod -a -G rvm <user>

Where <user> would be the user webide.

Installing a Ruby

Now add the following to each user's $HOME/.bashrc. I generally put this at the end of the file:

[[ -s /usr/local/rvm/scripts/rvm ]] && source /usr/local/rvm/scripts/rvm

With that, you'll want to logout and log back in.

NOTE1: It isn't enough to start another tab in gnome-terminal, it needs to be a newly logged in session. This is so that the group you just added this user to, get's picked up.

NOTE2: You'll probably not have to add the above to your $HOME/.bashrc if you find you have the following file installed here already, this does the above plus more for all users that are in the group rvm on the system.

$ ls -l /etc/profile.d/rvm.sh 
-rwxr-xr-x 1 root root 1698 Nov 27 21:14 /etc/profile.d/rvm.sh

Once logged in you'll need to install a Ruby. You can do this using the following steps, as user webide.

What versions available to install?

$ rvm list known | less
...
# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-p374]
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p320]
[ruby-]1.9.3[-p484]
[ruby-]2.0.0-p195
[ruby-]2.0.0[-p353]
[ruby-]2.1.0-preview2
[ruby-]2.1.0-head
ruby-head
...

NOTE: The 1st time you install a Ruby you should do this with a user that has sudo rights so that dependencies can be installed. For example on Ubuntu, you'll see this type of activity. After these are installed other users, such as webide, should be able to install additional Rubies too, into the directory /usr/local/rvm.

Installing requirements for ubuntu.
Updating system..............................................................................................................
Installing required packages: libreadline6-dev, zlib1g-dev, libssl-dev, libyaml-dev, libsqlite3-dev, sqlite3, autoconf, libgdbm-dev, libncurses5-dev, automake, libtool, bison, libffi-dev...............................................................................................
Requirements installation successful.

Viewing installed versions

$ rvm list

rvm rubies

 * ruby-1.9.3-p484 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

Installing a 2nd Ruby

$ whoami
webide

$ rvm install 2.0.0-p195
...
ruby-2.0.0-p195 - #validate binary
ruby-2.0.0-p195 - #setup
Saving wrappers to '/usr/local/rvm/wrappers/ruby-2.0.0-p195'........
ruby-2.0.0-p195 - #importing default gemsets, this may take time..................

Now when we list what's installed:

$ rvm list

rvm rubies

 * ruby-1.9.3-p484 [ x86_64 ]
   ruby-2.0.0-p195 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

From the above we can see that user webide was able to install a Ruby.

Setting a default for all rvm users

$ rvm use ruby-2.0.0-p195 --default
Using /usr/local/rvm/gems/ruby-2.0.0-p195

$ rvm list

rvm rubies

   ruby-1.9.3-p484 [ x86_64 ]
=* ruby-2.0.0-p195 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

Logging in as another user that's in the group rvm we can see the effects of making ruby-2.0.0-p195 the default.

$ rvm list

rvm rubies

=> ruby-1.9.3-p484 [ x86_64 ]
 * ruby-2.0.0-p195 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

So this user is using, ruby-1.9.3-p484, and he's now configured to use ruby-2.0.0-p195 as the default too.

Slow downloads/installs

If you're experiencing a slow download you might want to make use of the offline installation method instead. This will allow you to do a re-install later on. Or perhaps the download via this system is problematic, and you could download the RVM installer on one system, and then use scp to copy the installer to this system afterwards.

$ curl -L https://github.com/wayneeseguin/rvm/tarball/stable -o rvm-stable.tar.gz

See here, RVM in offline mode for full details.

References

Solution 2

since you are running a debian based distribution, the simplest way to install ruby would be to run the following as root (e.g. using sudo or whatever method you prefer):

 aptitude install ruby
Share:
29,378

Related videos on Youtube

user5321306
Author by

user5321306

Updated on September 18, 2022

Comments

  • user5321306
    user5321306 over 1 year

    I intend to use Ruby when programming my Raspberry Pi which is running the Debian based Occidentals. Via SSH, I executed:

    curl -L https://get.rvm.io | bash -s stable --ruby
    

    which downloaded the ruby source and compiled it. It tool about 2 hours to complete. I would like to use ruby via AdaFruit's WebIDE - http://learn.adafruit.com/webide/. However, the ruby installation I performed via SSH created a folder called .rvm in the pi user's directory, whereas the WebIDE uses the webide user account.

    What is the best way to allow the webide user account access to ruby? I tried moving the .rvm folder from /home/pi to /etc/share, but this didn't work - when trying to use ruby at a terminal I got the error "ERROR: Missing RVM environment file: '/home/pi/.rvm/environments/ruby-2.0.0-p353'" so I must've broken some link.

    I'm holding back running another 2hr install for the webide user as I'm sure there's a better way!

  • user5321306
    user5321306 over 10 years
    Thanks. If I were to now use your suggested method, can you suggest a way to clean up the previous installation? My linux is a tad rusty! As mentioned, there is a .rvm directory in the pi user's home directory, but I suspect there's some other configuration - see the error message in my post
  • user5321306
    user5321306 over 10 years
    I think I found it - rvm implode
  • user5321306
    user5321306 over 10 years
    Thanks. What kind of problems could using the repo version cause?
  • slm
    slm over 10 years
    Typically the versions of interpreters in the repo are meant for use by other software. True you can use them and most of the time it's a non-issue. But if you're doing any type of application development you want to maintain control of your app as well as the interpreter and Gems you're using. RVM is suited for this, the packages in the repos are not.
  • user5321306
    user5321306 over 10 years
    Hmmm... I've reinstalled RVM using the command you described and added the webide user to the rvm group, but still only the pi user has access to ruby.
  • user5321306
    user5321306 over 10 years
    I'm not getting beyond the "What versions available to install?" section as webide does not 'see' rvm. I've checked the /etc/passwd file in the hope of finding some differences between pi and webide as I don't think webide is a regular user - it was created as part of an ide installation. Here are the two entries from /ect/passwd: pi:x:1000:1000:,,,:/home/pi:/bin/bash webide:x:1001:1002::/home/webide:/bin/sh
  • user5321306
    user5321306 over 10 years
    I think I've sussed it - there is a slash missing in the line that goes into the .bashrc file. Strangely, the pi user works even with the incorrect path in the .bashrc file. I only spotted the error as the webide terminal is only accessible by a browser and it won't let me paste so I had to type it! Thanks a million for your help
  • slm
    slm over 10 years
    @barry - DOH! Sorry about the typo, fixed. Glad this fixed your issue. Do you think you'll stay with using this method over the aptitude one? If so, and you think this is a better answer, you might want to consider switching it to the accepted one. The only reason I ask is I'd rather see others in the future use this method over the repo'd version of Ruby, since it's better/easier method to support Ruby + your application deployments.