LoginSignup
0
2

More than 1 year has passed since last update.

llvmのリポジトリを追加してclangの最新版をインストールする

Last updated at Posted at 2023-01-18

準備

必要なパッケージをインストールします。

$ apt install curl gnupg

gpgキーの取得

llvmリポジトリのgpgを取得してきます。

$ curl -fsSL https://apt.llvm.org/llvm-snapshot.gpg.key | gpg --dearmor -o /etc/apt/keyrings/llvm.gpg

公式サイトではapt-keyを使用する方法が紹介されていましたが、非推奨のワーニングが出るためgpgを使用する方法にしました。

リポジトリの登録

取得してきたgpgキーと紐付けてllvmリポジトリを登録します。

$ echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/llvm.gpg] http://apt.llvm.org/jammy/ llvm-toolchain-jammy main" | tee /etc/apt/sources.list.d/llvm.list > /dev/nul

インストール

インストールします。

$ apt update
$ apt install clang llvm lld lldb
$ clang++ --version
Ubuntu clang version 16.0.0 (++20230116031321+5ab0894fd570-1~exp1~20230116151419.689)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

バージョンを指定してインストールする

下記のようにバージョンを指定してリポジトリを登録した場合は、インストールするときもバージョンを指定することになります。

 echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/llvm.gpg] http://apt.llvm.org/jammy/ llvm-toolchain-jammy-15 main" | tee /etc/apt/sources.list.d/llvm.list > /dev/nul
$ apt install clang-15 llvm-15 lld-15 lldb-15

実行するときはバージョン付きだとめんどくさいのでバージョン無しでもアクセスできるようにします。

$ update-alternatives --install /usr/bin/clang clang /usr/bin/clang-15 1
$ update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-15 1
$ update-alternatives --install /usr/bin/lldb lldb /usr/bin/lldb-15 1
$ update-alternatives --install /usr/bin/lld lld /usr/bin/lld-15 1
$ clang --version
Ubuntu clang version 15.0.7
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

参考サイト

  • 公式サイト

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2