Hugonweb | Building Clang From Source

See also: Building GCC From Source

Install the prereqs (for amd64 arch Ubuntu):

sudo apt install build-essential cmake

Download source from https://github.com/llvm/llvm-project/releases

Unpack the source code, cd into the source directory, mkdir build; cd build and then, replacing X.Y.Z with the version of clang you downloaded:

cmake -DCMAKE_INSTALL_PREFIX=/opt/clang-X.Y.Z -DCMAKE_EXECUTABLE_SUFFIX=-X.Y.Z -DLLVM_ENABLE_PROJECTS=clang -DCMAKE_BUILD_TYPE=Release -G "Unix Makefiles" ../llvm
nice make -j8
make install

You then must add /opt/clang-X.Y.Z/bin to your $PATH.