How to efficiently switch between different Ballerina versions in Ubuntu
Ballerina is a recently launched and strongly typed programming language with both textual and graphical syntaxes. By the time of this post is written, several versions of ballerina have been released with fewer faults than the previous version.
There can be situations where we might want to try different versions of Ballerina. Uninstalling and reinstalling different versions from time to time might be not the best way to handle such situations. Here is a procedure to overcome such situations successfully in Ubuntu and hopefully will work for other Linux distributions too.
Step 1: Download needed Ballerina distribution as .zip files, unzip them and save in a preferred location.
You can download the latest Ballerina version from https://ballerina.io/downloads/ and previous versions from https://ballerina.io/downloads/archived/.
Let’s use Ballerina v0.970.1 and v.0.975.0 as examples.
Step 2: Create two script files (.sh) with the following contents.
For v0.970.1
export BALLERINA_HOME=”<location-to-ballerina-versions>/ballerina-0.970.1";
export PATH=”${BALLERINA_HOME}/bin:${PATH}”;
and save using a preferred name but with the .sh extension. Let’s say bal_0.970.1.sh.
For v0.975.0
export BALLERINA_HOME=”<location-to-ballerina-versions>/ballerina-0.975.0";
export PATH=”${BALLERINA_HOME}/bin:${PATH}”;
Let’s save this as bal_0.975.0.sh.
You have to replace <location-to-ballerina-versions> with your location to ballerina distributions.
Step 3: Open the ‘bashrc’ file in the root using a text editor and enter following lines.
Opening using ‘gedit’
gedit ~/.bashrc
Opening using the vi editor
vi ~/.bashrc
Then add the following two lines.
alias bal_0.970.1=’source <location-to-script-files>/bal_0.970.1.sh’
alias bal_0.975.0=’source <location-to-script-files>/bal_0.975.0.sh’
You have to replace <location-to-script-files> with the location of script files.
Step 4: Open a terminal and type either ‘bal_0.970.1’ or ‘bal_0.975.0’ and the given version will start to run on that terminal.
In order to change the version, you can just insert the other version name. But one insertion of the ballerina version will only affect that particular terminal and you have t re-insert the version for another terminal.
Using this procedure you can switch between different Ballerina versions immediately and run multiple versions simultaneously.