18

How can I install clang on Ubuntu 18.04 LTS Bionic?

  • Add the results of apt-cache policy clang clang-6.0 clang-5.0 – doug Aug 1 '18 at 11:20
  • 2
    Please, post the output of sudo apt install clang-6.0... – Olimjon Aug 2 '18 at 17:24
  • sudo apt install clang-6. You can also do sudo apt install clang-7 and sudo apt install clang-8 – Boris Jan 31 at 14:33
16

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
| improve this answer | |
  • Reading package lists... Done Building dependency tree Reading state information... Done Some packages could not be installed. This may mean that you have requested an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or been moved out of Incoming. The following information may help to resolve the situation: The following packages have unmet dependencies: clang : Depends: clang-6.0 (>= 6.0~) but it is not going to be installed E: Unable to correct problems, you have held broken packages. – Bluetake Jul 23 '18 at 2:33
  • How can i fix this problem? – Bluetake Jul 23 '18 at 2:33
  • 1
    @steeldriver using the it I am getting the following error clang : Depends: clang-6.0 (>= 6.0~) but it is not going to be installed E: Unable to correct problems, you have held broken packages. How to fix it ? – Nithin Varghese Aug 1 '18 at 9:10
  • @NithinVarghese that's a rather generic error - there are some suggested fixes in this previous question Unable to correct problems, you have held broken packages among others – steeldriver Aug 1 '18 at 15:55
3

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
| improve this answer | |
  • 1
    Nope there was no lucking in doing so. – Nithin Varghese Aug 6 '18 at 18:26
  • @NithinVarghese You might need to ask your own question then showing the errors that you are getting. I have a 18.04 LTS installation and I just barely installed it this way and it worked fine. Without telling us errors, it is nearly next to impossible for us to guess what problems you are having during the installation. – Terrance Aug 6 '18 at 19:39
2

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
| improve this answer | |
  • 1
    I've tired this method before and it was futile as others. Do you have any clue what can be the cause of this – Nithin Varghese Aug 6 '18 at 18:30
  • I have tried and it worked for me. Can you disable other repos and try again ? – KK Patel Aug 6 '18 at 18:31
2

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
| improve this answer | |
0

You can do as users above shared

sudo apt-get install clang-6.0

just that i want to pay your attention to this interesting document : LLVM Debian/Ubuntu nightly packages

to get a complete vision how to install nightly packages.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.