Keep Ruby Gems in Your Home Directory
I like keeping my Ruby Gems in my home directory. I don’t have to type sudo in front of every gem command, it’s easier to remember the path to them when I want to read their source, and I don’t have to worry about a sysadmin on a shared host updating a gem before I test it. Here’s how to make those benefits yours:
Create or edit your .gemrc to read:
gemhome: /home/<i>your username</i>/.gems gempath: - /home/<i>your username</i>/.gems - /usr/lib/ruby/gems/1.8
Next, set up your login environment. Add these lines to the end of your .bashrc, .bash_profile, or .profile (whichever file you happen to already have — if you use another shell, you should already know what file is the equivalent).
export PATH=~/bin:~/.gems/bin:$PATH export GEM_HOME=/home/<i>your username</i>/.gems export GEM_PATH=/home/<i>your username</i>/.gems:/usr/lib/ruby/gems1.8
Last, add the following to your .ssh/environment so that gems work properly when you’re executing commands over ssh (for example, with capistrano).
PATH=~/bin:~/.gems/bin:/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin GEM_HOME=/home/<i>your username</i>/.gems GEM_PATH=/home/<i>your username</i>/.gems:/usr/lib/ruby/gems1.8
You’ll need to log out and back in to update your login environment, and then you’ll be able to run gem normally. All the files get stored in the directory ~/.gems if you want to look around.
Want more? I'm not as good at forgetting to update @pushcx on Twitter.
Conversation (0)
Jump to comment form | comments rss [?]Add this link to your feed reader to watch for new replies to this post. | trackback uri [?]Trackback this link in a blog post to create a comment here linking to your post.