Title: Permission errors installing gems on linux
Tags: ruby;gem;debian
Question: Seems like only root can use ruby gems (?)
$ gem list
*** LOCAL GEMS ***
$ gem install json
ERROR:  While executing gem ... (Errno75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0ES)
Permission denied - /var/lib/gems/1.9.1
I have no gems and can't install any...
$ sudo gem install json
[sudo] password for bill:
Building native extensions.  This could take a while...
Successfully installed json-1.8.0
1 gem installed
Installing ri documentation for json-1.8.0...
Installing RDoc documentation for json-1.8.0...
$ sudo gem list
*** LOCAL GEMS ***
json (1.8.0)
Root can install and view gems
$ gem list
*** LOCAL GEMS ***
But my user can't see them...
Is there a way for non-root users use gems on linux?
-- SOLUTION --
Thanks for the comments suggesting I check /var/lib/gems/1.9.1 permissions
I'd already checked them, but missed /var/lib/gems on the way
/var/lib/gems# ls -al
total 12
drwxr-x---  3 root root 4096 Oct  3 09:13 .
drwxr-xr-x 59 root root 4096 Oct  3 09:13 ..
drwxr-xr-x  6 root root 4096 Oct  3 09:13 1.9.1
chmod o+rx /var/lib/gems/
I can now use the gems already installed there
Comment: Not when Ruby is installed as root. You should try using RVM or RBenv.

Comment: Maybe try `chmod +wrx /var/lib/gems/1.9.1`

Comment: My guess is that users don't have read permissions to your gems directory

Comment: Could you run `ls -al /var/lib/gems/1.9.1` and show result.


Here is another answer: no, you shouldn't try rvm or rbenv as they are both terrible.  chruby is very lightweight and the best of a bad situation.
the answer is you should need sudo to install system-wide gems.
set GEM_HOME to ~/.gems or /path/to/app/.gems to install the gems per-user or per-app

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 4, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2013:00:10/03/13', 'FavoriteCount': 1.0, 'PostTypeId': 1, 'Tags': '<ruby><gem><debian>', 'Title': 'Permission errors installing gems on linux', 'ViewCount': 3634, 'id': 19161811, 'user_AboutMe': None, 'user_AccountId': 3387355.0, 'user_DisplayName': 'user2843054', 'user_Reputation': 31.0, 'user_Views': 2.0, 'user_id': 2843054.0}}