3

OS: Ubuntu 18.04

There are already some posts about how to install clang in Ubuntu, however many of them are out of date, and my question is specific to installing clang as part of the insallation of YouCompleteMe.

First, following the indications in this answer and in the link provided there, I ran these commands:

$ wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
$ sudo apt-get update && sudo apt-get upgrade
$ sudo apt-add-repository "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-8 main"

I then ran $ vim /etc/apt/sources.list and could verify that the new lines corresponding to llvm were added, as expected. I then ran:

$ apt-get install clang-8 lldb-8 lld-8 --print-uris

to get the information about disk space needed, which in this case was:

The following NEW packages will be installed:
binfmt-support clang-8 lib32gcc1 lib32stdc++6 libc6-i386 libclang- 
common-8-dev libclang1-8 libffi-dev liblldb-8 libobjc-7-dev libobjc4 
libomp-8-dev libomp5-8 libpfm4 libpython-stdlib lld-8 lldb-8
llvm-8 llvm-8-dev llvm-8-runtime python python-lldb-8 python-minimal 
python-six python2.7 python2.7-minimal
0 upgraded, 26 newly installed, 0 to remove and 0 not upgraded.
Need to get 71,4 MB of archives.
After this operation, 412 MB of additional disk space will be used.

Now, before actually installing those packages, I read again the README file of YouCompleteMe, and noticed it says:

You can use the system libclang or clangd only if you are sure it is version 8.0.0 or higher, otherwise don't. Even if it is, we recommend using the official binaries from llvm.org if at all possible. Make sure you download the correct archive file for your OS.
We STRONGLY recommend AGAINST use of the system libclang or clangd instead of the upstream compiled binaries. Random things may break. Save yourself the hassle and use the upstream pre-built libclang or clangd.

I guess that when they say "the system libclang", they refer to the libclang I was going to install using apt-get (Is this what they actually refer to? If someone knows what they mean by "system libclang", please let me know). So, I decided to follow the LLVM link provided by them. Once there, I clicked on "Ubuntu 18.04" under the section "Pre-built binaries". Then the download of the tar.xz file started, and I then ran:

$ tar -xJf clang*.tar.xz

And this post implies I should run:

$ cd clang*
$ sudo cp -R * /usr/local/

So now I see that I have two ways of installing clang: through apt-get, and by unpacking the binary.

Is YouCompleteMe asking for an unusual way of installing clang?
What is the right way to install clang in Ubuntu 18.04?

3
  • According to YouCompleteMe's instructions clang 8 from the default Ubuntu 18.04 repositories (sudo apt install clang-8) doesn't work with YouCompleteMe and instead they recommend installing their own pre-built binaries.
    – karel
    Jul 7, 2019 at 0:27
  • @karel thank you for the interest. I tried to to find the part where they mention this, using Ctrl+F, but could not find it. Could you please point me to where does it say that? In case it's related, I understand there is a part where they say the "system libclang" is not recommended; but what do they mean by "system libclang"?
    – evaristegd
    Jul 7, 2019 at 0:35
  • 1
    I checked and found "system libclang" in 18.04 which is a package named libclang1-8, so to install both clang-8 and libclang1-8 in Ubuntu 18.04 run sudo apt install clang-8 libclang1-8
    – karel
    Jul 7, 2019 at 2:54

1 Answer 1

3

I'm sure that system libclang and clangd are version 8.0.0 or higher in Ubuntu 18.04.

clangd is provided by clang-tools-8 from the universe repository in Ubuntu 18.04. Clang 8 and libclang are provided by clang-8 and libclang1-8 oackages in Ubuntu 18.04. To install all of these packages open the terminal and type:

sudo apt install clang-8 libclang1-8 clang-tools-8  

I also found the official binaries from llvm.org which is a 325 MB file named clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.gz. This contains the upsteam compiled binaries that are mentioned in the README file of YouCompleteMe. Manually downloading and installing 325 MB of files seems like a lot of work to me just to install a code-completion engine for Vim which is only a 1,152 kB download and 2,852 kB installed for vim itself, so I would try installing YouCompleteMe with the Ubuntu repository packages first and check if using system packages breaks anything in YouCompleteMe.

9
  • 1
    Thanks for the answer. I was thinking installing YCM with the Ubuntu repository packages might break something in Ubuntu. In the YCM manual they say "Random things may break", but do not specify which things. What do you think?
    – evaristegd
    Jul 7, 2019 at 13:05
  • 2
    That's not possible. In fact it means the exact reverse, that random things may break in the YouCompleteMe plugin for Vim, but it won't break Vim itself or anything else in Ubuntu 18.04. Installing software from the default Ubuntu 18.04 repositories is completely safe. Furthermore installing 325 MB of relatively untrusted software as a dependency of a plugin for a 1,152 kB package is a massively disproportionate waste of disk space, especially if that disk is an SSD.
    – karel
    Jul 7, 2019 at 13:07
  • Got it, thanks. One more thing, YouCompleteMe has more than 19k stars in GitHub. So, what is it that Ubuntu users (or Linux users in general) usually do when installing YouCompleteMe? It's hard to imagine for me that I am the first one dealing with this conundrum.
    – evaristegd
    Jul 7, 2019 at 13:16
  • 2
    I've dealt with this conundrum myself. I can't control the whole world of software developers on GitHub, so my first priority is to control package management in Ubuntu to be what it should be. I don't do anything dodgy with package management except by sandboxing it in some type of virtual environment. I think it's worth a try to try using software from the default Ubuntu repositories as dependencies for YCM first.
    – karel
    Jul 7, 2019 at 13:26
  • Thanks for the replies. Regarding the apt command written in your answer, should I run it with the LLVM repository added to /etc/apt/sources.list ? Or without it? I am asking because, from what I understand, the LLVM repository is not part of the default Ubuntu repositories.
    – evaristegd
    Jul 7, 2019 at 13:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .