Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I install clang-format in Ubuntu?

I am trying to use clang-tools in particular clang-format for automatic code formatting in vim but I couldn't find this tool with apt-get search.

Is there anybody experienced this problem before, do you have any suggestion?

like image 287
Validus Oculus Avatar asked Dec 24 '13 07:12

Validus Oculus


People also ask

Where is clang-format Ubuntu?

clang-format is not available in the ubuntu-precise 12.04 but it is available in ubuntu saucy http://packages.ubuntu.com/saucy/clang-format-3.4. Show activity on this post. You can check https://apt.llvm.org/ if your operating system is not on this list.

How do I get clang on Ubuntu?

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.

How do I download clang-format?

You can install clang-format and git-clang-format via npm install -g clang-format . To automatically format a file according to Electron C++ code style, run clang-format -i path/to/electron/file.cc . It should work on macOS/Linux/Windows.

Where is clang-format installed?

Standalone Tool clang-format is located in clang/tools/clang-format and can be used to format C/C++/Java/JavaScript/JSON/Objective-C/Protobuf/C# code.


2 Answers

clang-format is not available in the ubuntu-precise 12.04 but it is available in ubuntu saucy http://packages.ubuntu.com/saucy/clang-format-3.4.

in order to find this package with the apt-cache we have to add below list into our repository list. Actually below list is generated for the singapore servers but if you want to look for your own country you can use http://repogen.simplylinux.ch/generate.php

After generating your list, you have to add them into your repository, you can learn how to do that by looking to here. https://help.ubuntu.com/community/Repositories/CommandLine

The list of packages are;

deb http://sg.archive.ubuntu.com/ubuntu/ saucy main restricted universe multiverse   deb-src http://sg.archive.ubuntu.com/ubuntu/ saucy main restricted universe multiverse   deb http://sg.archive.ubuntu.com/ubuntu/ saucy-security main restricted universe multiverse   deb http://sg.archive.ubuntu.com/ubuntu/ saucy-updates main restricted universe multiverse   deb http://sg.archive.ubuntu.com/ubuntu/ saucy-proposed main restricted universe multiverse   deb http://sg.archive.ubuntu.com/ubuntu/ saucy-backports main restricted universe    multiverse   deb-src http://sg.archive.ubuntu.com/ubuntu/ saucy-security main restricted universe multiverse   deb-src http://sg.archive.ubuntu.com/ubuntu/ saucy-updates main restricted universe multiverse   deb-src http://sg.archive.ubuntu.com/ubuntu/ saucy-proposed main restricted universe multiverse   deb-src http://sg.archive.ubuntu.com/ubuntu/ saucy-backports main restricted universe multiverse  

Then you should search clang-format with below command first

sudo apt-cache search clang-format

Then, you can install which version you want to install such as;

sudo apt-get install clang-format-3.3

like image 42
user2760375 Avatar answered Oct 09 '22 16:10

user2760375


With Ubuntu 16.04, simply do:

sudo apt install clang-format

like image 55
user218867 Avatar answered Oct 09 '22 15:10

user218867