Ubuntu Linux comes with alternatives – a command-line utility to create and maintain symbolic links to default commands. This utility can be found in many Linux distributions; however, this guide was specifically written for and tested on Ubuntu 11.10.
Here is how you can use alternatives to install and configure apache-ant.
-
Download and extract
apache-ant-1.6.5:
wget http://archive.apache.org/dist/ant/binaries/apache-ant-1.6.5-bin.tar.bz2
tar xvf apache-ant-1.6.5-bin.tar.bz2
-
Repeat for
apache-ant-1.8.2(or any other version you may need):
wget http://archive.apache.org/dist/ant/binaries/apache-ant-1.8.2-bin.tar.bz2
tar xvf apache-ant-1.8.2-bin.tar.bz2
-
Check if apache-ant is already installed and move its binaries to the “stock” directory:
test -f /usr/share/ant || sudo mv /usr/share/ant /usr/share/apache-ant-stock -
Move
apache-ant-1.6.5to/usr/share:
sudo mv apache-ant-1.6.5 /usr/share/
-
Move
apache-ant-1.8.2to/usr/share:
sudo mv apache-ant-1.8.2 /usr/share/
-
Use
alternativesto map/usr/share/apache-ant-1.6.5to/usr/share/ant, which is Ubuntu’s default location for theapache-antbinaries:
update-alternatives --install /usr/share/ant ant-bins /usr/share/apache-ant-1.6.5 1
-
Add
/usr/share/apache-ant-1.8.2:
update-alternatives --install /usr/share/ant ant-bins /usr/share/apache-ant-1.8.2 2
-
Re-add the “stock”
apache-antbinaries to be provided byalternatives:
update-alternatives --install /usr/share/ant ant-bins /usr/share/apache-ant-stock 3
-
Use
alternativesto the map/usr/share/apache-ant-1.6.5/bin/antexecutable to/usr/bin/ant:
update-alternatives --install /usr/bin/ant ant /usr/share/apache-ant-1.6.5/bin/ant 1
-
Map the
/usr/share/apache-ant-1.8.2/bin/antexecutable to/usr/bin/ant:
update-alternatives --install /usr/bin/ant ant /usr/share/apache-ant-1.8.2/bin/ant 2
-
Add the “stock” executable to
alternatives:
update-alternatives --install /usr/bin/ant ant /usr/share/apache-ant-stock/bin/ant 3
-
Configure
alternativesto use theapache-ant-1.6.5binary directory:
update-alternatives --config ant-bins
-
Configure
alternativesto use theapache-ant-1.6.5binaries to provideant:
update-alternatives --config ant
-
Verify that
apache-antis properly configured for version 1.6.5:
ant -version