How to install a specific version of GCC on Ubuntu 11.04 (natty)

Sometimes you need to install a specific version of gcc for some reasons, for example when you need to have the same compiler version as the one used by your team.

In that, the package manager doesn't help because not every version of gcc is packaged in every version of Ubuntu. So you must install it by hand and it can take a little time and there is some things that has to be done in order to work.

I'm talking here of Ubuntu 11.04 (natty), because this is the version I installed Ubuntu on. This procedure will certainly work but you could have a problem with some dependencies that are installed in natty and not in your version or in the contrary have a dependency already installed.

So this article will detail every step to install a specific version of gcc

Personally, I've made the whole installation from the folder ~/dev/ . You can use this folder or use another one, but I recommend to you use an empty folder for that. When I will talk about the installation, I will refer to this folder.

Note 1 : Because I wanted this new gcc to be my main compiler, I've directly installed everything in /usr/local/. If you want to install it in a specific folder, you can use the --prefix=FOLDER option fo the ./configure command. If you make so, you don't have to use the sudo before the make install unless you choose another directory where you don't have the right to write in.

Note 2 : If you have a multicore processor, you should use the -jX option with make where X is your number of core (you can make it +1).

Building gcc requires several libraries that are not installed by default. Let's start with GNU Multiple Precision Library (GMP). You can download the latest version (5.0.2 now) here : . Decompress the library in your installation folder and then use the followings commands :

cd gmp_dir
make check
sudo make install

You should have a message indicating that the libraries have been installed in your folder.

After that, you can install the GNU MPFR library (version 3.0.1 now), available here : . Unzip the file in your installation folder and type the following commands :

cd mpfr_dir
make check
sudo make install

You should see the same confirmation message than for the last installation. Then, you can install the last library, MPC (version 0.9 now), that you can download here : . Once again, unzip the file and your installation folder and launch the same commands :

cd mpfr_dir
make check
sudo make install

Same confirmation message.

To prepare the installation of gcc, you have to type the given two commands :

export C_INCLUDE_PATH=/usr/include/x86_64-linux-gnu 
export CPLUS_INCLUDE_PATH=/usr/include/x86_64-linux-gnu 

Here we are, you are ready to install gcc. Download the version you want to install here : and extract it on your installation folder.

Note : for those who have installed the first three libraries in different folder you have to indicate to ./configure where they are using the given command line options : --with-gmp=FOLDER, --with-mpfr=FOLDER and --with-mpg=FOLDER

Note : I installed gcc for C and C++, if you want to select other languages just tune the --enable-languages option and if you want every language, just remove this option.

Then create a directory on the same level as gcc sources dir :

cd installation_folder
mkdir build
cd build

and now from this folder, we can install everything :

../gcc_dir/configure --enable-languages=c,c++
sudo make install

Now it's time to take a coffee (or even two), because the full compilation can take a lot of time.

When the compilation is finished, you can try it with this command

gcc --version

that should give you the version you just installed. If it is not the case, verify that you did every step and if it's the case, take a look at the official installation guide

Related articles

  • Ubuntu Lucid Lynx (10.04) is here !
  • Install the JR environment on Windows
  • Install the Insight Debugger on Linux Mint (works for Ubuntu too)
  • Tip : How to switch from KUbuntu to Ubuntu
  • Switching to Gentoo Linux
  • Getting started with Play Framework
  • Comments

    Comments powered by Disqus