Ubuntu – How to update Apache Ant version from 1.9.3 to 1.9.4

apache-antjava

My O.S. version is Ubuntu 14.04 LTS.

My Apache ant version is 1.9.3.

ant -version
Apache Ant(TM) version 1.9.3 compiled on April 8 2014

I want to update my Apache ant 1.9.4.(onwards)

Please help me, because when I'm using sudo apt-get install ant to update my ant.

But after this sudo command ant it showing following messages.

ant is already the newest version.

The following packages were automatically installed and are no longer
required:

aspectj eclipse-platform-data eclipse-rcp fastjar jarwrapper junit4
libasm3-java libaspectj-java libbonoboui2-0 libbonoboui2-common
libcommons-beanutils-java libcommons-cli-java libcommons-codec-java
libcommons-collections3-java libcommons-compress-java
libcommons-dbcp-java libcommons-digester-java
libcommons-httpclient-java libcommons-lang-java libcommons-pool-java
libdb-java libdb-je-java libdb5.3-java libdb5.3-java-jni
libeasymock-java libecj-java libequinox-osgi-java
libfelix-bundlerepository-java libfelix-gogo-command-java
libfelix-gogo-runtime-java libfelix-gogo-shell-java
libfelix-osgi-obr-java libfelix-shell-java libfelix-utils-java
libgeronimo-jpa-2.0-spec-java libgeronimo-jta-1.1-spec-java
libgeronimo-osgi-support-java libglade2-0 libgnomecanvas2-0
libgnomecanvas2-common libgnomeui-0 libgnomeui-common
libhamcrest-java libicu4j-4.4-java libicu4j-java libjetty8-java
libjline-java libjtidy-java libkxml2-java liblucene2-java
libosgi-compendium-java libosgi-core-java libosgi-foundation-ee-java
libservlet2.5-java libswt-cairo-gtk-3-jni libswt-glx-gtk-3-jni
libswt-gnome-gtk-3-jni libswt-gtk-3-java libswt-gtk-3-jni
libswt-webkit-gtk-3-jni libtomcat7-java libxz-java
linux-headers-3.13.0-32 linux-headers-3.13.0-32-generic
linux-image-3.13.0-32-generic linux-image-extra-3.13.0-32-generic
linux-signed-image-3.13.0-32-generic sat4j Use 'apt-get autoremove'
to remove them. 0 upgraded, 0 newly installed, 0 to remove and 7 not
upgraded.

Best Answer

Open up a Terminal with (Ctrl + t)

Remove the installed Ant either by remove or purge:

$ sudo apt-get purge ant

The output should be something like

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  ant* ant-optional*
0 upgraded, 0 newly installed, 2 to remove and 13 not upgraded.
After this operation, 3,057 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 310491 files and directories currently installed.)
Removing ant-optional (1.9.3-2build1) ...
Removing ant (1.9.3-2build1) ...
dpkg: warning: while removing ant, directory '/usr/share/ant/lib' not empty so not removed
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...

(I have a jar file in '/usr/share/ant/lib' which I need so I didn't clean that up.)

Download, verify signature, unpack and put the Apache Ant to for example /opt/ (According to their website it is suggested to use the latest version, but we specifically need 1.9.4, right? :-))

~$ cd Downloads
~/Downloads$ wget https://archive.apache.org/dist/ant/binaries/apache-ant-1.9.4-bin.tar.gz
~/Downloads$ wget https://www.apache.org/dist/ant/KEYS
~/Downloads$ wget https://archive.apache.org/dist/ant/binaries/apache-ant-1.9.4-bin.tar.gz.asc

~/Downloads$ gpg --import KEYS
~/Downloads$ gpg --verify apache-ant-1.9.4-bin.tar.gz.asc apache-ant-1.9.4-bin.tar.gz
~/Downloads$ gpg --fingerprint 82A7FBCD

~/Downloads$ tar -xvzf apache-ant-1.9.4-bin.tar.gz
~/Downloads$ sudo mv apache-ant-1.9.4 /opt/

More information about Apache Signature Verifying:

https://www.apache.org/info/verification.html

Create a symlink to your bin folder so your programs can call it

$ sudo ln -s /opt/apache-ant-1.9.4/bin/ant /usr/bin/ant

Usually your programs will need the ANT_HOME and ANT_OPTS environment variables:

### ANT-SETUP
export ANT_HOME="/opt/apache-ant-1.9.4"
export ANT_OPTS="-Xmx1024m"

To make it permanent put the above lines to ~/.bashrc. Here are the commands to do this: Either use an editor to edit .bashrc or from command line, just use the below commands.

Create a backup of .bashrc, before doing anything with it.

$ cp ~/.bashrc ~/.bashrc-backup

$ echo "" >> ~/.bashrc
$ echo "### ANT-SETUP by $USER" >> ~/.bashrc
$ echo "export ANT_HOME=\"/opt/apache-ant-1.9.4\"" >> ~/.bashrc
$ echo "export ANT_OPTS=\"-Xmx1024m\"" >> ~/.bashrc

Verify that the changes are correct

$ diff ~/.bashrc ~/.bashrc-backup

The output should be something like:

129,130c129
< 
< ### ANT-SETUP by ${your_username}
< export ANT_HOME="/opt/apache-ant-1.9.4"
< export ANT_OPTS="-Xmx1024m"
---
> 

Restart the Terminal or source the .bashrc

$ source ~/.bashrc

Verify the installation:

$ ant -diagnostics
Related Question