How to Install GMP in Ubuntu (5 Steps)

By Allen Bethea

GMP is used to build programs that perform fast, high-precision arithmetical calculations.
i Mike Watson Images/moodboard/Getty Images

Although Ubuntu ships with its own implementation of the GNU Multiple Precision Arithmetic Library already installed, if you need the latest and most complete version of the software, you will need to download, compile and install it yourself. The compressed GMP archive contains all the source code and configuration utilities you need as well as a suite of demonstration programs you can build to test the libraries.

Step 1

Download the latest stable version of GMP's source code from the developer's website using the link found in Resources.

Step 2

Launch a Terminal session, extract the GMP archive's contents into the folder you downloaded it to and then set the extracted source code folder as your active directory. For example, if you downloaded the file "gmp-6.0.0a.tar.lz" from the GMP website, open the extracted "gmp-6.0.0" folder.

Step 3

Build the makefile for GMP. The configure script will examine your system to see that all of GMP's hardware and software dependencies are met and then build the makefile that contains the compiler commands necessary to create binary library files. For example, if you are working with a new install of Ubuntu, the configure script will let you know that you need to install the M4 macro processor first. To build the makefile, type the following command at the command prompt and press "Enter:"


If you need to install M4 or any other dependency, run the "./configure" command again.

Step 4

Build GMP's binary library files with the Make command. Make compiles and links all the individual components of the GMP library. Type "make" at the command prompt and then press "Enter." Compilation may take awhile to complete. For example, GMP version 6.0 consists of 2581 individual files that must be pre-processes, compiled, assembled and linked.

Step 5

Install GMP's libraries on your system. While you can compile GMP as a normal user, you will need root permission and the sudo command to install the libraries to your system. Type the following command at the terminal prompt, press "Enter," type your password and then press "Enter" to install GMP.

sudo make install

GMP's library files will be stored in the /usr/local/lib folder. The GMP library files that Ubuntu installs by default, however, remain /usr/lib/i386-linux-gnu/ on 32-bit systems or usr/lib/x86_64-linux-gnu/ on 64-bit systems. If a program you use needs the version of GMP you compiled, you will have to configure it to look for the libraries in the /usr/local/lib directory instead.