In this guide, we will walk you through the steps of installing GCC on a server running Debian 9 using two different methods: using the APT package manager (Advanced Package Tool), and installation from source.
GCC, also known as the GNU Compiler Collection, is developed by Richard Stallman and was released by the Free Software Foundation. GCC is a very useful and widely-used collection of programming compilers, such as C, C++, Objective-C, Fortran, Objective-C++, Java, Go, and Ada. GCC is an official compiler of the GNU operating system, but it is also a standard compiler on many Unix operating systems such as Linux. Let’s get started with the installation.
- VPS hosting plan with Debian 9 OS
- System user with root privileges. (All our VPS hosting plans come with full root access)
- Build-essential package, which contains several packages essential for building Debian packages including gcc compiler, make and other required tools.
Step 1. Log in and Update the Server
Login to your Debian 9 VPS via SSH as user root
ssh [email protected]IP_Address -p Port_Number
Replace IP_Address and Port_Number with the actual IP and SSH port for your server.
Update all installed packages on the server by running the following command:
apt update && apt upgrade
It is recommended to always keep your services updated whenever a new version comes out. This maximizes security and compatibility between packages.
Step 2: Install GCC
Method 1: Install GCC from a Repository
GCC is available in the official Debian 9 repositories and it can be easily installed using the APT package manager. To install GCC on your server, run the following command:
apt -y install gcc
This will install GCC and all its necessary dependencies. Once the installation completes, you can execute the following command to check the version of GCC installed on your server
gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516 Copyright (C) 2016 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
As you might see from the output, GCC version 6.3.0 is installed, which is not the latest release. The current stable version of GCC at the time of the article being written is version 8.2, and if you want to install it on your server, you can check the next step.
Method 2: Install GCC from Source
If you need a more recent version of GCC than 6.3.0 which at the moment of writing this article is the latest one distributed with Debian 9, you can install GCC from source. Download the archive of GCC version 8.2 to your server. This version has some prominent changes, new features, and improvements over its predecessors.
cd /opt wget http://ftp.mirrorservice.org/sites/sourceware.org/pub/gcc/releases/gcc-8.2.0/gcc-8.2.0.tar.gz
Unpack the downloaded tarball and change the working directory:
tar zxf gcc-8.2.0.tar.gz cd gcc-8.2.0
Execute the following script to download some prerequisites required by GCC
You should get an output similar to this one:
ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2  -> "./gmp-6.1.0.tar.bz2"  ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2  -> "./mpfr-3.1.4.tar.bz2"  ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz  -> "./mpc-1.0.3.tar.gz"  ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-0.18.tar.bz2  -> "./isl-0.18.tar.bz2"  gmp-6.1.0.tar.bz2: OK mpfr-3.1.4.tar.bz2: OK mpc-1.0.3.tar.gz: OK isl-0.18.tar.bz2: OK All prerequisites downloaded successfully.
At this point, we are ready to configure GCC 8.2. Install the
build-essential package and run the following command to start configuring GCC for the install process:
apt -y install build-essential ./configure --disable-multilib
After the configuration completes, compile the source code by running the following command. NOTE: Depending on the server’s resources, the compiling may take a while:
make -j 4 make install
Once the compilation is completed, execute the following command verify that GCC version 8.2 is properly installed on your server:
gcc --version gcc (GCC) 8.2.0 Copyright (C) 2018 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
With this step, the process of installing the latest version of GCC on your Debian 9 server has been completed. If you need more information about GCC, its usage, configuration, and features, you can check GCC’s official documentation.
Of course, you don’t have to install GCC on Debian 9 if you use one of our Managed Server Support services, in which case you can simply ask our expert Linux admins to install and configure GCC for you, along with anything else that you might need. They are available 24×7 and will take care of your request immediately.
PS. If you liked this post on how to install GCC on Debian 9, please share it with your friends on the social networks using the share shortcuts, or simply leave a reply in the comments section. Thanks.