4 steps to use alternatives (multi-version manager)

Dear reader,

Today I will show how to manage multiple application version . Indeed when you use the classical way as yum install … or whatever you can not to have multiple version.

I see often people that install multiple version anywhere and after you have to set  env var as PATH, LD_LIBPATH, PYTHONPATH

For this task they are a nice tool named alternatives. This tool is mainly used to have an open java and the proprietary, then we miss to often, that it could to be used for others application. This tool is not to manage only a java environment. You can to use it for any software.

I use it to have multiple version of:

They are no limit.

I will show how i do for the D compiler you could adapt easily for your software. That is not the easier software to use through alternatives like this you will see what you can to do and how.

 

1/ Grab the Software

DMD his hosted on github and it need phobos and druntime, to get all do:

×
+

Terminal

$ for project in dmd druntime phobos; do
    [[ ! -e ${project} ]] && git clone https://github.com/D-Programming-Language/${project}.git
    pushd ${project}
    git pull
    git checkout remotes/origin/2.065
    popd
done
$

2/ Build your application

This part is unnecessary, if you have directly the binary.

The command below will build : dmd, druntime, phobos

×
+

Terminal

$ for project in dmd druntime phobos; do
    pushd ${project}
    make -f posix.mak -j4 clean all
    popd
done
$

3/ Installing your application

I install external software into  /opt and i follow this convention: /opt//

And alternatives will link the given version to /usr/local/ . Into /opt I have all versions for a given application and into /usr/local only application with a specific version.

For this we need to create the directory into /opt

×
+

Terminal

$ mkdir -p /opt/dmd/2.065/bin /opt/dmd/2.065/lib64 /opt/dmd/2.065/include/d
$

And now we have just to install build files into these directory:

×
+

Terminal

$ cp     dmd/src/dmd /opt/dmd/2.065/bin
$ cp -ur druntime/import/* /opt/dmd/2.065/include/d/
$ cp     druntime/lib/*.a /opt/dmd/2.065/lib64/
$ cp     phobos/generated/linux/release/64/lib* /opt/dmd/2.065/lib64/
$ cp -ur phobos/std phobos/etc /opt/dmd/2.065/include/d/
$

Add a little configuration file into bin directory

×
+

Terminal

$ cat <<eof> /opt/dmd/2.065/bin/dmd.conf
[Environment] DFLAGS=-I/opt/dmd/2.065/include/d -L-L/opt/dmd/2.065/lib64 -L–no-warn-search-mismatch -L–export-dynamic
eof
$

4/ Run alternatives

×
+

Terminal

# su –
# alternatives –install /usr/local/bin/dmd dmd /opt/dmd/2.065/bin/dmd 26500 \
     –slave /usr/local/bin/dmd.conf dmd.conf /opt/dmd/2.065/bin/dmd.conf \
     –slave /usr/local/lib64/libphobos2.so.0.65.0 libphobos2.so.0.65.0 /usr/local/lib64/libphobos2.so.0.65.0 \
     –slave /usr/local/lib64/libphobos2.so.0.65 libphobos2.so.0.65 /usr/local/lib64/libphobos2.so.0.65 \
     –slave /usr/local/lib64/libphobos2.so libphobos2.so /usr/local/lib64/libphobos2.so \
     –slave /usr/local/lib64/libdruntime-linux64.a libdruntime-linux64.a /usr/local/lib64/libdruntime-linux64.a \
     –slave /usr/local/lib64/libdruntime-linux64so.a libdruntime-linux64so.a /usr/local/lib64/libdruntime-linux64so.a \
     –slave /usr/local/lib64/libcurl_stub.so libcurl_stub.so /usr/local/lib64/libcurl_stub
$

Here we said to alternatives to bind dmd which is located at /opt/dmd/2.065/bin/dmd to /usr/local/bin/dmd.

As the priority I use always the version here: 26500 for dmd major version 2 minor 65 and bump 00 .

Note: Always fill on two digits (or more if need) as here 0 become 00. That is important example you have version 2.64.11 and 2.65.0 which could give 26411 and 2650. But Alternatives will think that 2.64.11 is newer than 2.65.0.

slave parameter tell to alternatives which file it need to provides when this version is choose.

You can invoke:

×
+

Terminal

$ alternatives –auto dmd
$

This will set dmd with highest priority ( in our case the latest version )

You can specify a version by giving the name and his path to desired version as:

×
+

Terminal

$ alternatives –set dmd /opt/dmd/2.064/bin/
$

With this you will switch to an older version

Share Button

Leave a Reply