Sometimes you need to use different Erlang versions for different projects. I personally have to use an old R12B-5 for one of my projects, which won’t compile on any of the latest Erlang versions. The question is then:
How to switch from one version of Erlang to another one in a simple way?
There are no magics behind what I’m going to say in this post. Actually, this post will sound quite trivial to most of you. I simply wanted to share what I currently do with the ones of you who might have the same need. I’m using Snow Leopard, but all of the above should apply to any UNIX-like system. Also, I assume you’re fine with installing Erlang from source.
Assume you have two separate Erlang installations in your home directory:
~/erlang13b04
~/erlang14a
Notice that you can specify the installation path of Erlang by selecting, at installation time:
./configure –prefix=YOUR_INSTALLATION_PATH
First of all, let’s edit our ~/.bashrc, by adding the following line:
PATH=$PATH:$HOME/bin
Then, let’s create the bin folder under the home directory:
mkdir $HOME/bin
Let’s now create some scripts in the directory we’ve just created. We will need one script for each installation we want to use.
Let’s create a file called “13″ (no extension). Inside the file, we write:
#!/bin/bash env PATH=/User/[USERNAME]/erlang13b04/bin:$PATH "$@"
Let’s then do the same for R14. Create a file named “14″ and write the following into it:
#!/bin/bash env PATH=/User/[USERNAME]/erlang14a/bin:$PATH "$@"
Make the two script executable:
cd ~/bin
chmod +x 13 14
Let’s “source” the ~/.bashrc (or simply open a new shell):
source ~/.bashrc
That’s it. If you want to run a command using R13, just:
13 erl
Erlang R13B04 (erts-5.7.5)
Eshell V5.7.5 (abort with ^G)
1>
Or:
14 erl
Erlang R14A (erts-5.8)
Eshell V5.8 (abort with ^G)1>
Assuming you have a project you want to compile with R13:
13 make
Or, if you prefer R14:
14 make
Well, you should have got the idea at this point…
Notice that you can still specify the path of your favourite (default) Erlang installation in your ~/.bashrc file, so you wan’t need to prepend “14″ to your commands every time you want to use the latest Erlang version.
As I’ve already said, there’s nothing special here. Just a bit of playing with paths that might turn useful from time to time.
You could also add the following to your ~.bashrc, instead of creating two scripts:
Posted by Misha | March 29, 2011, 1:05 pm