Earlier this week I noticed that my MacBook Pro’s 256GB hard disk was 95% full, which prompted me to start investigating what I could remove in order to free up space.
Having remembered that on a previous occasion a work colleague had suggested using ncdu, I started this very helpful tool and task-switched whilst waiting for it to finish.
When I delved into what ncdu had to show me about large files, I eventually made an interesting discovery.
After regaining some space by deleting some Apple Mail log files, I was surprised to find many git versions of some internal RubyGems that we use at work. Some of these are large. All of them are referred to in Gemfiles by their GitHub repositories, or in other words they are git referenced gems defined in the Gemfile like this:
gem 'blake-data-source', git: 'email@example.com:blake-education/blake-data-source.git', branch: 'develop'
The result was this:
That’s right. The gems for Ruby 2.1.2 were taking up 10.5GB of disk space! Looking closely, I could see that there were many old versions of large gems.
One way of cleaning up old versions of gems is to use the
gem cleanup command. However, whilst this will remove old versions of gems that have been tagged with version numbers, it won’t include git referenced gems in it’s sweep.
In my case I had to be aware that, since this command would clean up gem versions unused in my directory, it would also clean up gems used by other projects using the same Ruby version.
Advice from my colleague Josh Kunzmann quickly allowed me to see the solution. That was to run
bundle clean --force and then change to using the
bundle install --path command, or
bundle --path for short. As the documentation says, the
--path option allows you to:
Specify a different path than the system default ($BUNDLE_PATH or $GEM_HOME). Bundler will remember this value for future installs on this machine
And, since I am in the habit of using bash aliases and tmuxinator, I am now using aliases like this to start project coding sessions:
alias mkp='bundle --path ~/.appgems/kpdotcom --clean && mux kp'
In this way I should be able to keep the disk space used by RubyGems under control. It also ensures that dependent gem versions are installed before I fire up tmuxinator.
The moral of the story is twofold:
bundle --path your/chosen/path --cleanis a good way to ensure that old versions of git referenced gems do not accumulate
Last night I deployed a new release of a Rails app.
Having deployed apps built with Rails 3 or at the very least Rails 2 apps using Bundler, the experience of deploying a Rails 2.3.5 app left me with a keen desire to at least bring this app up to Rails 2.3.11 with Bundler.
One of the delights of last night’s deployment was having to update RubyGems on the target machine. Usually this is as simple as:
gem update --system
That is, unless you are forced to upgrade to a specific, old release of RubyGems. Being at Rails 2.3.5 with this app, we were in this situation.
Speaking of “not exactly state of the art”, the version of Ruby on the target machine is Ruby Enterprise Edition 1.8.6.
Obviously, the preferred option would be to upgrade to Ruby 1.9.2 and Rails 3.0.5 forthwith.
However, it’s not my money that will be funding the upgrade. First steps first. I’m aiming for the following path:
Wish me luck!