Skip to content

Instantly share code, notes, and snippets.

@andreanidouglas
Created July 26, 2022 21:17
Show Gist options
  • Save andreanidouglas/5a64639796dda72634f3e0eb0fba646f to your computer and use it in GitHub Desktop.
Save andreanidouglas/5a64639796dda72634f3e0eb0fba646f to your computer and use it in GitHub Desktop.
How to install Carbon Language on Ubuntu 22.04

How to install carbon language on Ubuntu 22.04

Make sure you have basic tools

sudo apt update && sudo apt -y install build-essential git curl gdb make cmake ninja-build meson

Install Go

curl -4 -L -O --url 'https://go.dev/dl/go1.18.4.linux-amd64.tar.gz'
# wget https://go.dev/dl/go1.18.4.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.18.4.linux-amd64.tar.gz 
export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin #or add to your .bashrc then source it

Install Baselisk

go install github.com/bazelbuild/bazelisk@latest

Install clang-14 and define as default

sudo apt install -y llvm-14 clang-14
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-14 100
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-14 100

Install dependencies and execute bazelisk to install compile carbon

sudo apt install libunwind-14-dev zlib1g-dev libllvm14 libc++-14-dev
export CC=clang # if you don't define this, it will try with GNU-GCC which will fail
export CXX=clang++ # if you don't define this, it will try with GNU-G++ which will fail
bazelisk run //explorer -- ./explorer/testdata/print/format_only.carbon

Exemple hello world

// hello_world.carbon
package Hello api;
fn Main -> i32 {
    var s: auto = "Hello World";
    Print(s);
    return 0;
}

Execute it

bazelisk run //explorer -- hello_world.carbon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment