C++ Software Setup: Linux Edition
As described in this week's lessons, in CS 70 we use the Clang compiler.
There are other C++ compilers out there, but we'll stick with Clang here to be consistent with what's on the server.
But you're free to look into other options on your own time!
Step 1: Install the Clang Compiler
To begin, open a terminal. The exact name of the terminal app in Linux varies by distro, but it's usually something like “Terminal”, “Console”, or “Konsole”.
Next, in the terminal, you'll use the system's package manager—a tool that allows you to install, uninstall, and update software packages—to install Clang. Different Linux distributions use different package managers, but these days most distros use either “debs” (originally created for the Debian distro) or RPMs (originally created for the Red Hat distro).
For Debian or Ubuntu (and Debian or Ubuntu derivatives such as Mint and Pop!_OS)
sudo apt install clang
For Fedora/Red Hat and derivatives
sudo dnf install clang
The sudo at the start of these command lines tells the system to run the command that follows it as “root”, which allows it to make changes to files and directories that regular users can't change. Then we have the package-manager command, followed by install clang to tell it to install the clang package.
When you hit Return, the system will prompt you to enter your password, which is the password you use to log into your computer.
Once you've authenticated, depending on what's already installed on your machine, you may see a list of additional packages the package manager needs to install for Clang to work. If so, say yes and let it do its thing.
Checking Your Clang Installation
To test whether the installation worked, run the following command in the terminal:
clang++ --help | head
You should see the first ten lines of what's actually a massive chunk of documentation for the Clang compiler (over 1800 lines!), which should start with something like the following:
OVERVIEW: clang LLVM compiler
USAGE: clang [options] file...
OPTIONS:
Step 2: Install Git
The process for installing Git is very similar. Just run the same package-manager command as you did before, but replace clang with git. If you install Git within a few minutes of installing Clang, you won't even need to type your password again.
Checking the Git Installation
You can quickly test that Git is working by running
git --help
This should print a ~50-line help summary that starts with something like the following:
usage: git [-v | --version] [-h | --help] [-C <path>] [-c <name>=<value>]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
[--config-env=<name>=<envvar>] <command> [<args>]
Step 3: Install GitHub CLI
GitHub CLI is a command-line interface for GitHub, and it's the easiest way to authenticate with GitHub from your own machine—which you'll be doing once you finish this page.
In most distributions the GitHub CLI package is just called gh (which is also the name of the program you run to do things). So, as above, you run sudo apt-get install gh, sudo dnf install gh, or an equivalent for your particular distro. You may get another list of additional packages gh needs; install them too.
Do I need this
ghthing at all?
There are other ways to authenticate with GitHub. If you search for
ssh authentication with GitHub, you'll find instructions for setting up SSH keys, which is another way to authenticate with GitHub. But GitHub CLI is the easiest way to do it.
Step 4: Install Helix (Recommended, but Optional)
Helix is the text editor we use on the CS 70 server, and if you install it on your machine, you can do your work just like you would on the server. Unfortunately, Helix is the one piece of the toolchain that isn't packaged the same way everywhere, so installing it is a bit more complicated.
On Fedora, Red Hat Enterprise Linux and derivatives, the package is called helix, so run
sudo dnf install helix
On Debian, it's hx, so
sudo apt-get install hx
On Ubuntu and derivatives, Helix isn't available in the standard package repositories (not in 24.04 LTS, which is what the CS 70 server itself runs) so the easiest route is to use the Snap package, with
sudo snap install --classic helix
Once it's installed, you start it by typing hx.
Meh. Do I have to use Helix?
Nope. We wanted you to be able to use the same terminal-based editor that we use on the server, but you're free to use any text editor you like, as long as it does not have AI code completion enabled.
I want MORE editors!! So of course I want Helix on my computer, too!
(When logged in, completion status appears here.)