Install GCC on an Ubuntu VPS

GCC (GNU Compiler Collection) is a compiler system produced by the GNU Project supporting various programming languages such as C, C++, Objective-C, Fortran, Java etc… GCC is a key component of the GNU toolchain and the standard compiler for most Unix-like Operating Systems. It has played an important role in the growth of free software, as both a tool and an example.

Requirements

We will be using our LC VPS-1 Linux Cloud VPS hosting plan running Ubuntu 16.04

Log in to your server via SSH

# ssh root@server_ip

You can check whether you have the proper Ubuntu version installed on your server with the following command:

# lsb_release -a

You should get this output:

Distributor ID: Ubuntu
Description:    Ubuntu 16.04.1 LTS
Release:        16.04
Codename:       xenial

Update the system

Make sure your server is fully up to date using:

# apt update && apt upgrade

Install GCC

It’s actually very easy to install GCC on Ubuntu. Once you update the package index you only need to run the below command:

# apt-get install gcc

In case you want to install a specific version of GCC use:

# apt-get install gcc=VERSION

Once the installation is completed, you can check which version of GCC you have:

# gcc -v

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.4.0-6ubuntu1~16.04.4' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4)

Another way to check which GCC packages are installed including dependencies is the below command:

# dpkg -l 'gcc*' | grep ^i

ii  gcc                4:5.3.1-1ubuntu1       amd64        GNU C compiler
ii  gcc-4.7-base:amd64 4.7.4-3ubuntu12        amd64        GCC, the GNU Compiler Collection (base package)
ii  gcc-5              5.4.0-6ubuntu1~16.04.4 amd64        GNU C compiler
ii  gcc-5-base:amd64   5.4.0-6ubuntu1~16.04.4 amd64        GCC, the GNU Compiler Collection (base package)
ii  gcc-6-base:amd64   6.0.1-0ubuntu1         amd64        GCC, the GNU Compiler Collection (base package)

To further understand GCC and its use you can check the respective MAN page. Below is a part of the GCC MAN page:

GCC(1)                                                                                               GNU                                                                                               GCC(1)

NAME
       gcc - GNU project C and C++ compiler

SYNOPSIS
       gcc [-c|-S|-E] [-std=standard]
           [-g] [-pg] [-Olevel]
           [-Wwarn...] [-Wpedantic]
           [-Idir...] [-Ldir...]
           [-Dmacro[=defn]...] [-Umacro]
           [-foption...] [-mmachine-option...]
           [-o outfile] [@file] infile...

       Only the most useful options are listed here; see below for the remainder.  g++ accepts mostly the same options as gcc.

DESCRIPTION
       When you invoke GCC, it normally does preprocessing, compilation, assembly and linking.  The "overall options" allow you to stop this process at an intermediate stage.  For example, the -c option
       says not to run the linker.  Then the output consists of object files output by the assembler.

       Other options are passed on to one stage of processing.  Some options control the preprocessor and others the compiler itself.  Yet other options control the assembler and linker; most of these are
       not documented here, since you rarely need to use any of them.

       Most of the command-line options that you can use with GCC are useful for C programs; when an option is only useful with another language (usually C++), the explanation says so explicitly.  If the
       description for a particular option does not mention a source language, you can use that option with all supported languages.

       The gcc program accepts options and file names as operands.  Many options have multi-letter names; therefore multiple single-letter options may not be grouped: -dv is very different from -d -v.

       You can mix options and other arguments.  For the most part, the order you use doesn't matter.  Order does matter when you use several options of the same kind; for example, if you specify -L more
       than once, the directories are searched in the order specified.  Also, the placement of the -l option is significant.

       Many options have long names starting with -f or with -W---for example, -fmove-loop-invariants, -Wformat and so on.  Most of these have both positive and negative forms; the negative form of -ffoo
       is -fno-foo.  This manual documents only one of these two forms, whichever one is not the default.

OPTIONS
   Option Summary
       Here is a summary of all the options, grouped by type.  Explanations are in the following sections.

       Overall Options
           -c  -S  -E  -o file  -no-canonical-prefixes -pipe  -pass-exit-codes -x language  -v  -###  --help[=class[,...]]  --target-help --version -wrapper @file -fplugin=file -fplugin-arg-name=arg
           -fdump-ada-spec[-slim] -fada-spec-parent=unit -fdump-go-spec=file

       C Language Options
           -ansi  -std=standard  -fgnu89-inline -aux-info filename -fallow-parameterless-variadic-functions -fno-asm  -fno-builtin  -fno-builtin-function -fhosted  -ffreestanding -fopenacc -fopenmp
           -fopenmp-simd -fms-extensions -fplan9-extensions -trigraphs -traditional -traditional-cpp -fallow-single-precision  -fcond-mismatch -flax-vector-conversions -fsigned-bitfields  -fsigned-char
           -funsigned-bitfields  -funsigned-char

       C++ Language Options
           -fabi-version=n  -fno-access-control  -fcheck-new -fconstexpr-depth=n  -ffriend-injection -fno-elide-constructors -fno-enforce-eh-specs -ffor-scope  -fno-for-scope  -fno-gnu-keywords
           -fno-implicit-templates -fno-implicit-inline-templates -fno-implement-inlines  -fms-extensions -fno-nonansi-builtins  -fnothrow-opt  -fno-operator-names -fno-optional-diags  -fpermissive
           -fno-pretty-templates -frepo  -fno-rtti -fsized-deallocation -fstats  -ftemplate-backtrace-limit=n -ftemplate-depth=n -fno-threadsafe-statics  -fuse-cxa-atexit -fno-weak  -nostdinc++
           -fvisibility-inlines-hidden -fvtable-verify=[std|preinit|none] -fvtv-counts -fvtv-debug -fvisibility-ms-compat -fext-numeric-literals -Wabi=n  -Wabi-tag  -Wconversion-null  -Wctor-dtor-privacy
           -Wdelete-non-virtual-dtor -Wliteral-suffix -Wnarrowing -Wnoexcept -Wnon-virtual-dtor  -Wreorder -Weffc++  -Wstrict-null-sentinel -Wno-non-template-friend  -Wold-style-cast -Woverloaded-virtual
           -Wno-pmf-conversions -Wsign-promo

That’s it. GCC is installed on your server and ready for use.

Of course, if you use one of our Ubuntu Cloud VPS Hosting services, all you have to do is ask our expert Linux admins to install GCC or offer some advice on how to use it. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

Leave a Comment