Using direnv to manage tool versions
At Electric Imp, we use a variety of different languages, and each project might be using a different mix of versions.
Until recently, we’ve been using kerl to manage Erlang versions, kiex to manage Elixir versions, rvm to manage Ruby versions and nvm to manage node versions. We’ve also been using virtualenv to manage Python 2.x virtual environments. We don’t deliberately manage Go versions (yet).
Yes, we do use all of those languages – and more – at Electric Imp.
For experimentation, I also have Rust, Haskell and OCAML installed on my development PC. These are out of scope (for now).
But: kerl, kiex and nvm only manage the installation of different versions. They don’t automatically switch to the correct version as you switch between projects.
For this, I’ve been using direnv.
But: direnv and rvm don’t play well together.
Our operations – #DevOps – team recently switched from rvm to rbenv, but that only covers Ruby versions. So I decided to try asdf for managing versions for everything.
That … didn’t work out so well.
- pip is broken
- bundler can’t install native extensions
- Some of our scripts directly use
nvm use, which complains about the node prefix being set. That is: both asdf and nvm want to manage the node version; they don’t play well together.
- We have a shonky script that expects
erlto be the real thing, not asdf’s shim. That’s our fault, but it makes team adoption harder.
So I’m going back to direnv, but with some knobs on.
This forms the first of a series of blog posts:
- Using direnv to manage tool versions (this post; 30 Jan 2019 17:00)
- Installing direnv (30 Jan 2019 17:01)
- Building Erlang: Prerequisites (Ubuntu) (30 Jan 2019 17:02)
- Installing kerl (30 Jan 2019 17:03)
- Integrating direnv with kerl (30 Jan 2019 17:03)
- Installing Erlang with kerl (30 Jan 2019 17:04)
- Getting Erlang version (30 Jan 2019 17:05)
- Integrating direnv with kiex (30 Jan 2019 17:07)
- Installing kiex (30 Jan 2019 17:10)
- Installing Elixir with kiex (30 Jan 2019 17:12)
- Integrating direnv with nvm (30 Jan 2019 17:12)
- Installing Python with python-build (30 Jan 2019 17:20)
- Integrating direnv with python-build (30 Jan 2019 17:25)
- Installing Ruby with ruby-install (30 Jan 2019 17:40)
- Integrating direnv with ruby-install (30 Jan 2019 17:45)
- Integrating direnv with ghc (2 Feb 2020 15:32)
- Integrating direnv with python 3 (12 Jun 2020 18:15)
.direnvrc file is in my
dotfiles repo: https://github.com/rlipscombe/dotfiles/blob/master/direnvrc