50

I'm having trouble getting clang++ to work as I compile my code. Specifically, I'm getting a make: clang++: Command not found error.

I've run sudo apt-get install llvm, and also sudo apt-get install build-essential and sudo apt-get update. What do I have to do to get clang++ installed?

Eliah Kagan
  • 117,780
user313944
  • 1,601

4 Answers4

44

Installing the llvm and build-essential packages, as you have done, does not cause clang or clang++ to be installed. For that, you must install one of the clang packages, depending on which version of clang and clang++ you want.

16.04

In Ubuntu 16.04, your options are clang-3.5, clang-3.6, clang-3.7, and clang-3.8.

14.04

In Ubuntu 14.04, your options are clang-3.3 Install clang-3.3, clang-3.4 Install clang-3.4, and clang-3.5 Install clang-3.5.

You can install them in the Software Center, or with:

sudo apt-get update
sudo apt-get install clang-3.n

(Replacing n with the desired sub-version, of course.)

12.04

If you're running Ubuntu 12.04, there's only one package that provides clang and clang++, so it's just called clang Install clang.

Eliah Kagan
  • 117,780
  • is there a chance to install clang from source without sudo? after making and make check-all, i tried to use make install, but lots of permission denied appeared. – Amir Nov 08 '14 at 21:59
  • "clang-3.5" link produces "404 Page not found." – CW Holeman II Feb 18 '15 at 02:24
  • 2
    clang-3.6 is available on their download page for ubuntu 14.04: http://llvm.org/releases/3.6.0/clang+llvm-3.6.0-x86_64-linux-gnu-ubuntu-14.04.tar.xz – David 天宇 Wong Apr 10 '15 at 16:10
  • @C.W.HolemanII I don't know why that's happening. The clang-3.5 package does seem to exist for 14.04, yet you are right that the Software Center link for it doesn't work. I don't have a 14.04 system to test this on right now. Can someone with (and with the universe repository enabled) check the output of apt list clang\*? – Eliah Kagan Apr 10 '15 at 16:16
  • clang/trusty 1:3.4-0ubuntu1 amd64 is the output of apt list clang. And upon installing clang, I got this list as remarked to be install: clang-3.4 libclang-common-3.4-dev libclang1-3.4 libobjc-4.8-dev libobjc4 – Peter Teoh Jul 04 '15 at 23:56
  • 1
    With 14.04 (trusty-updates), clang-3.6 is also available. – Josh Milthorpe Jul 25 '16 at 14:35
  • 3
    At least for me, on 14.04 with clang-3.8 installed, I added a soft link for clang++ (by default, I only had /usr/bin/clang++-3.8). For example: sudo ln -s /usr/bin/clang++-3.8 /usr/bin/clang++. – rkersh Jan 27 '17 at 17:34
  • 2
    Can we get a more updated version of this answer? – Nathan majicvr.com Jun 15 '18 at 05:40
  • 1
    @frank currently clang-5.0 is the newest version: https://packages.ubuntu.com/search?keywords=clang-5.0 – zhangxaochen Mar 18 '19 at 16:23
  • @Amir Sure you can. ./configure --prefix $HOME/somewhere Then when you make and make install, it installs it in your home directory where you said. Then you simply PATH=$HOME/somewhere:$PATH, and there you go, this terminal will find it. You can set your bash so it will just set PATH like that always, in your .bashrc or something. – doug65536 Mar 29 '23 at 18:06
27

18.04 (Bionic)

I visited http://apt.llvm.org/bionic/dists/ (i.e. bionic distributions).
I determined that 6.0 was the latest major version of the toolchain.

I assume that you'll want the linker, lld, also.

# grab the key that LLVM use to GPG-sign binary distributions
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo apt-get update
sudo apt-add-repository "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-6.0 main"
sudo apt-get install -y clang-6.0 lld-6.0

This gives you binaries with the following names (and more, probably):

clang-6.0
clang++-6.0
lld-6.0
ld.lld-6.0

It also installs these packages (and more):

llvm-6.0
llvm-6.0-dev
llvm-6.0-runtime

17.04 (Artful)

Same as above. I'll repeat every line for convenient copy-paste.

# grab the key that LLVM use to GPG-sign binary distributions
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo apt-get update
sudo apt-add-repository "deb http://apt.llvm.org/artful/ llvm-toolchain-artful-6.0 main"
sudo apt-get install -y clang-6.0 lld-6.0

16.04 (Xenial)

The accepted answer already gives instructions for installing clang-3.8 on 16.04, but here's how to get clang-6.0:

# grab the key that LLVM use to GPG-sign binary distributions
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo apt-get update
sudo apt-add-repository "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-6.0 main"
sudo apt-get install -y clang-6.0 lld-6.0
Birchlabs
  • 371
  • 3
  • 6
9

Before proceeding it will be worthwhile to update package information using sudo apt-get update

Installing Clang 9 on Ubuntu 18

sudo apt-get install clang-tools-9

It will also install llvm-9

For more information follow clang documentation.

Installing Clang 10 on Ubuntu 18

sudo apt-get install clang-tools-10

2

22.04LTS (Jammy)

sudo apt-get install -y clang-14 lld-14

Found latest release here: https://packages.ubuntu.com/jammy/clang-14

Contango
  • 121
  • 3
  • 3
    This does not install clang++ as well, you need to run sudo apt install clang afterwards. – Mecanik Dec 07 '22 at 05:05
  • 2
    Not for me. Flutter demanded it and it only worked when i used simple sudo apt install clang – Sami Sep 15 '23 at 11:07