1. Home
  2. Linux
  3. Clang on ubuntu

How to install Clang on Ubuntu

The Clang compiler is an alternative to GCC. It can be used to compile code into runnable binary programs. If you’re a developer on Ubuntu, you’ve likely dealt with a compiler like this before.

While most Ubuntu developers stick with GCC, they also make it possible to get going with the Clang compiler. If you’re looking to get Clang working on Ubuntu, this guide is for you! Follow along as we show you how to get Clang 9, Clang 11, and Clang 12 working on Ubuntu.

install Clang on Ubuntu

How to install Clang 9 on Ubuntu

If you need to get Clang 9 working on Ubuntu, you’ll be happy to know that most Ubuntu releases, even Ubuntu 21.04, the latest release, have it in its software repository. To get going with Clang 9, start by opening up a terminal window. 

To open up a terminal window on the Ubuntu desktop, press Ctrl + Alt + T on the keyboard. Once it is open, use the apt install command below to install the Clang 9 package. Be sure to use the –install-suggests command-line switch, as it will tell Ubuntu to grab everything you need to use Clang 9.

sudo apt install clang-9 --install-suggests

Following entering this command in a terminal window, Ubuntu will prompt you to enter a password. Do so. When you do, it will collect all suggested packages for you to install on your PC. 

After Ubuntu collects all the packages for you to install, you’ll be prompted to press the key on the keyboard. Press the key on the keyboard to confirm that you wish to proceed with the installation. 

Upon pressing Y, Ubuntu will install Clang 9 on your system. When done, close the terminal window, or begin using Clang 9 in the command line.

How to install Clang 11 on Ubuntu 

For one reason, Ubuntu doesn’t have Clang 10, but it does have Clang 11, which is better due to its being a newer release. If you need Clang 11 on your Ubuntu system, start by opening up a terminal window.

To open up a terminal window on the Ubuntu desktop, press Ctrl + Alt + T on the keyboard. Or, search for “Terminal” in the app menu. Once it is open, use the apt install command and the –install-suggests command-line switch to get Clang 11 set up, along with Ubuntu suggested packages.

sudo apt install clang-11 --install-suggests

Upon entering the command above, Ubuntu will prompt you to enter a password to continue. Using the keyboard, type out your user account password. Then, press the Enter key on the keyboard to proceed.

After proceeding, Ubuntu will collect all suggested packages and get them ready for installation. Following that, you’ll be asked to press the button to continue. Using the key on the keyboard, confirm you wish to continue with the installation, and Ubuntu will install Clang 11.

When the installation is complete, Clang 11 will be on your Ubuntu PC. From here, you can close the terminal or begin using Clang 11.

How to install Clang 12 on Ubuntu 

In addition to Clang 9 and Clang 11, Clang 12 is also available on Ubuntu for users to install if they need it. If you’d like to install Clang 12 on your Ubuntu PC, start by opening up a terminal window. To open up a terminal window on Ubuntu, press Ctrl + Alt + T or Ctrl + Shift + T on the keyboard.

Once the terminal window is open and ready to use, enter the apt install command and install the “clang-12” package, along with the –install-suggests command-line switch, which grabs all suggested packages.

sudo apt install clang-12 --install-suggests

After entering the command above to install Clang 12, Ubuntu will prompt you to enter a password. Passwords are required for sudo commands. Using the keyboard, enter your user account’s password, and press the Enter key.

When you enter your password in the command-line prompt and press the Enter key, Ubuntu will collect all packages that Clang 12 needs. From there, it’ll ask you to press the key. Do so.

Ubuntu will begin to download and install all Clang 12 packages on your computer upon pressing the Y key. This will only take a couple of seconds. When the process is complete, close the terminal window, or keep it open and use Clang 12.

Other Clang packages

If you require other Clang packages on Ubuntu not covered in this post, do yourself a favor and check out Pkgs.org. It indexes many mainstream Linux package repositories, including Ubuntu’s, and you can use it to search for any Clang package you need.

In addition, be sure also to check out the official Ubuntu package search. It’s a website dedicated to all Ubuntu packages across all distributions. You’ll be able to use it to search for any Clang package you need!