Setting Up Your Linux Machine for Google’s Carbon Programming Language

And printing “Hello World”

Mwanikii
3 min readJul 27, 2022
Photo by Safar Safarov on Unsplash

A few days ago, Google announced the release of a new programming language developed to be a “successor language” to C and C++. One of the main reasons highlighted is the presence of technical debt during the development of C and C++ applications.

As the programming language is new and there may not be enough information for a beginner in the Linux world to navigate, I found it relevant to break down the information present in Carbon’s documentation. I stumbled on a few problems but I think my suggestions will come in handy when setting up your machine to run Carbon.

Prerequisites

Homebrew

Java JDK

A desire to learn

Local Installation

On Carbon’s Github repo, there is an assumption that someone already has homebrew up and running on their system.

It is necessary to install homebrew in order to proceed with the next important step. You can achieve this by pasting the below code on your terminal.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

After pressing enter, homebrew will be installed on your system.

The next step is to add homebrew to your path through the terminal:

echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> /home/"user"/.profileeval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"

Input your username in the place indicated “user” above.

The next step would be to install the Java JDK recommended for your system in order to run bazelisk as recommended in Carbon’s Github.

Their main site recommends:

# Ubuntu 16.04 (LTS) uses OpenJDK 8 by default:
sudo apt install openjdk-8-jdk

# Ubuntu 18.04 (LTS) uses OpenJDK 11 by default:
sudo apt install openjdk-11-jdk

Now we can follow the steps provided by Carbon’s read me file to ensure that our system can run it.

# Install bazelisk using Homebrew.
$ brew install bazelisk
# Install Clang/LLVM using Homebrew.
# Many Clang/LLVM releases aren't built with options we rely on.
$ brew install llvm
$ export PATH="$(brew --prefix llvm)/bin:${PATH}"
# Download Carbon's code.
$ git clone https://github.com/carbon-language/carbon-lang
$ cd carbon-lang
# Build and run the explorer.
$ bazel run //explorer -- ./explorer/testdata/print/format_only.carbon

This will automatically give you “Hello World” as a response when executed. The last line runs the code in the file “format_only.carbon” that looks as follows:

package ExplorerTest api;fn Main() -> i32 {
var s: auto = "Hello world!";
Print(s);
return 0;
}

The screenshot below is a picture of the result:

Hello World! by author

Note:

It is not advisable to attempt to install the requirements manually as it is tedious and problematic.

I would otherwise encourage anyone to start tinkering with this to see how much potential you can extract out of this new exciting programming language.

Sources:

[1]https://github.com/carbon-language/carbon-lang

--

--

Mwanikii

Writer. Techie. History buff. If it changes the world I’m on its case. Open for gigs… freddynjagi@gmail.com! Published by the Writing Cooperative.