How To Install the GMP Library on Ubuntu

How To Install the GMP Library on 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: https://gmplib.org/#DOWNLOAD.
  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
    ~/Desktop/GMP

    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:
    ./configure

    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:
    make

    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!

28 thoughts on “How To Install the GMP Library on Ubuntu

  1. This post was useful to me. Sometimes people don’t have enough time to go into the details, making guides like this valuable.

  2. I think you may forget –enable-cxx option when typing in the command ./configure, if you wants to use GMP in C++ codes 🙂

  3. Wonderful. It works. I use R programming. The GMP library installation showing error there. But after installing the GMP library as per your instruction, I’ve installed gmp in R successfully.
    Thanks for your deep and system-level suggestions.

  4. I am using Ubuntu Single user system and I needed to use
    sudo make install
    to get the .h files made and moved to the usr … libraries
    All working well. Thankyou for the step-by-step instructions.
    Greatly appreciated

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to top