Installing clang 6.0 on Ubuntu 18.04 LTS Bionic

How can I install clang on Ubuntu 18.04 LTS Bionic?


Solution 1:

clang-6.0 is (at least currently) the default version of clang on Bionic:

$ apt-cache depends clang
clang
  Depends: clang-6.0
  Breaks: <clang-3.2>
  Breaks: <clang-3.3>
  Breaks: <clang-3.4>
  Breaks: <clang-3.5>
  Replaces: clang
  Replaces: <clang-3.2>
  Replaces: <clang-3.3>
  Replaces: <clang-3.4>
  Replaces: <clang-3.5>


$ apt-cache policy clang-6.0
clang-6.0:
  Installed: 1:6.0-1ubuntu2
  Candidate: 1:6.0-1ubuntu2
  Version table:
 *** 1:6.0-1ubuntu2 500
        500 http://ca.archive.ubuntu.com/ubuntu bionic/universe amd64 Packages
        100 /var/lib/dpkg/status

So, you just enable the universe repository and then install clang - either from the software store or from the command line using

sudo apt update
sudo apt install clang

Solution 2:

Adding to @steeldriver's answer, clang is a dependency package providing the default clang version, which is 6.0 in Bionic.

You may have better luck installing the clang-6.0 package directly:

sudo apt-get update
sudo apt-get install clang-6.0

Solution 3:

You can install clang-6.0 on Ubuntu 18.04 using official LLVM repository.

wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -

sudo apt-add-repository "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-6.0 main"

sudo apt update && sudo apt install clang-6.0

Solution 4:

You might be missing some necessary channels from sources.list.

Step 1: Backup your repositories and remove repository lists other than sources.list.

Step 2: Do sudo gedit /etc/apt/sources.list and make it look like this:

deb http://archive.ubuntu.com/ubuntu bionic main multiverse restricted universe
deb http://archive.ubuntu.com/ubuntu bionic-security main multiverse restricted universe
deb http://archive.ubuntu.com/ubuntu bionic-updates main multiverse restricted universe

Save and exit.

Step 3: Update your repository:

sudo apt update

Step 4: Install clang-6.0:

sudo apt install clang-6.0