How To Handle Two Versions of autoconf?
Have two versions of autoconf in your system? And you require both frequently? Learn how to handle the situation.
Although I mentioned Autoconf exclusively, but the same steps can be followed for any other program too. For example if you want to manage multiple versions of
What is autoconf?
GNU Autoconf is a tool for producing configure scripts for building, installing and packaging software on computer systems where a Bourne shell is available. Autoconf is agnostic about the programming languages used, but it is often used for projects using C, C++, Fortran, Fortran 77, Erlang or Objective-C.
Wikipedia contributors. (2019, June 22). Autoconf. In Wikipedia, The Free Encyclopedia. Retrieved 19:20, June 26, 2019, from https://en.wikipedia.org/w/index.php?title=Autoconf&oldid=903003352
For my GSoC project, I need to port some codes in Newlib. As other good projects, Newlib also uses Autoconf tools for producing “Makefile.in” and various other useful scripts.
Newlib can be cloned from its git repository.
git clone git://sourceware.org/git/newlib-cygwin.git
The situation is, inside its source tree,
newlib-cygwin/uses autoconf tools version 2.64.
autoconf tools version 2.69 .
As I mostly work on terminal, when I run
autoconf command, it calls the 2.69 version.
Linux Environment Variable “$PATH”
Ever wondered whenever you run a program in a shell, how the shell is able to locate it and run it?
For example, the command,
whoami is present inside
/usr/bin directory. How your shell identifies to pick this particular program from its specific location?
Well, it doesn’t. To get clear, open your terminal and run the command
This the path variable of my Linux Environment:
What happens when you run
Linux doesn’t know what is
whoami and where it is located. It does everything with the help of its environment variable
The locations are written in priority order in
$PATH variable. When you run
- First it checks inside
usr/local/bindirectory for any program with that name.
- Then it checks inside
- Then it checks inside
usr/bindirectory. Here it found a program name
whoami, hence it runs it.
- As the program is found, it will never check the other mentioned paths.
Since the autoconf version 2.69 is stored inside
/usr/bin , whenever I run it, it calls
2.69 version .
Download “autoconf 2.64” source and build it
Move inside extracted folder, and open the terminal in that directory. Run following commands:
You will find your compiled 2.64 version of autoconf tools inside
Now the path of your autoconf tools version 2.64 is
Adding it to the “$PATH”
Now, we know how
$PATH works. So to run 2.64 version, we what we need to do is, we need to add the path to 2.64 version in the beginning of
$PATH variable. Hence when we will call
autoconf , it will first search inside
/opt/autoconf-2.64/bin directory, find the program and run it.
To do this, simply run:
$PATH , you can see the output will be like:
/opt/autoreconf-2.64/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:........so on .
Hence the path to 2.64 version tools is prefixed to
$PATH . Thus it gets the highest priority. Thus, when we will run any of the autoconf tools, it will run the 2.64 version.
(Note if you run
export PATH=$PATH:/opt/autoconf-2.64/bin instead of
export PATH=/opt/autoconf-2.64/bin:$PATH , the path will get suffixed, and it will get the least priority.).
Managing the versions.
As now we have figured out the way to run 2.64 version, whenever I need to run
autoreconf -fvi (2.64) version, I just run
export PATH=/opt/autoconf-2.64/bin:$PATH before it.
And when I need to run
autoreconf -fvi (2.69) version, I just run
export PATH=/usr/bin:$PATH before it.
Follow this Publication for more stories on this subject. If you find this blog helpful, please click the 👏 button and share to help others find it! Feel free to leave a comment 💬 below :).