How To Install the GMP Library on Ubuntu

how to install gmp ubuntu

In my Data Structures and Algorithms II class (more like Algorithms and Algorithms class), our professor assigned us to write a RSA encryption program to complement our coursework on modular arithmetic and primality testing. Because we needed large numbers (1024 bits) which would absolutely not fit inside normal primitive data types, we were suggested to use the GMP library for C++, or BigInteger for Java. Being a C++ guy, I choose GMP.

Now, what I found out while writing this lab was that installing GMP was actually harder than writing the program! To cut to the chase, here is how to download and install GMP onto your Ubuntu system. This approach uses the source file downloaded from GMP’s official page and the Ubuntu terminal.

Installing the GMP Library

No pictures today because the instructions are quite simple and straightforward.

  1. Download the lastest release of GMP from:
  2. When you have downloaded the file, extract the contents from the tar.lz file to a temporary folder. I created my temporary folder on my desktop for simplicity’s sake.
  3. Once extracted, open your terminal and wiggle your way to the temporary folder’s directory. For example, mine would be at

    If you forgot, the “ls” command displays the list of items in your current directory, and the “cd” command can be used to go to specific locations. “cd ..” can be used to go back to the previous directory.

    cd Desktop/GMP
  4. Once at the directory, type in the command:

    To what I understand, “./configure” will check your system to see if all the dependencies are met, and then create the makefile.

  5. (Optional) If you are met with the error: No usable M4 in $PATH or /usr5bin, then you need to install the M4 macro processor onto your Ubuntu system. Luckily, doing so is quite easy if you have Internet access. You must have root access as we will be using sudo apt-get:
    sudo apt-get install m4

    Don’t forget to run “./configure” again once you are done!

  6. Now you are ready to build the GMP library’s files, awesome! Proceed with the command:

    Do note that this process may take a few minutes for some computers. For mine (Ubuntu virtualized within Windows), it took me around 3 minutes. The terminal window will start printing out words in supersonic speed. If you have a friend nearby, grab him over so you can tell him you’re hacking GMail’s servers.

  7. When you are ready to install the library, type in this command:
    sudo make install
  8. GMP’s documentation prompts us to check to see if our installing was correct. To do so:
    make check

If no errors show up, congratulations. You now have GMP installed!

Kevin Lin

I am a senior at Wake Forest University currently pursuing my BS in Computer Science, and I love technology! To learn a little more about me, please visit the "Meet Kevin" widget on the top right on the screen!
Posted in C++, Programming.

5 Responses

Leave a Reply

Your email address will not be published. Required fields are marked *