I recently created a private gem repository for gems that I use at work that are not public. Searching for ‘create gem repository’ yields plenty of hits, but I had a couple of bumps along the journey that I thought I would detail here to help anyone else that might need it.
I use rvm pretty religiously, but I’m not going to involve it in these instructions. For those that need rvm, you’ll know what to do.
#Here We Go#
The steps to building a repo are pretty simple, really.
- Create a directory to host your gems.
Copy your gems to /var/www/gem-repo/gems
Install the builder gem version 2.1.2. This was my first bump. Most instructions omit the version. It appears that builder 3.0 does not function properly in this situation. I received a variety of errors before I switched. Worked fine after that.
- Generate the repo index
- Create a virtual host on your web server that points to /var/www/html/gem-repo.
- Add the source to your clients that need access to it. Don’t do this yet if you want to add a password, described below.
- Verify that it was added:
- When you have a new gem to add or update, simply perform steps 2 and 4 again.
This being a private gem repository, it seemed a good idea to me to password protect it. I’ll use the .htaccess method, which I’m aware is not that secure. If somebody wants my gems bad enough, they’ll get them. Congratulations.
- Add the proper allow to the server config. On apache, this is
Generate a .htpasswd file. I like to use http://www.4webhelp.net/us/password.php for that. Save the file wherever you feel is secure on your system.
Create .htaccess in /var/www/html/gem-repo. It should look like this:
- After a restart of your web server, your gems are password protected. You’ll need a different source.
The alternative to setting up your own server is moving gem files around to where you need them, when you need them. Just say no.