Installing & Building RISC-V Toolchain

RISC-V
A walkthrough of installing and building the RISC-V toolchain from scratch on Ubuntu 20 LTS.
Published

May 21, 2021

This post walks you through how to install and build the RISC-V toolchain from scratch.

Prerequisites

  • Install git on your system:
sudo apt install git-all
  • A Linux machine (tested on Ubuntu 20 LTS).
  • Sufficient storage — around 30 GB free.
  • Install a few dependencies:
sudo apt-get install autoconf automake autotools-dev curl python3 \
  libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison \
  flex texinfo gperf libtool patchutils bc zlib1g-dev libexpat-dev

Create a directory and clone

mkdir risc-v
cd risc-v
git clone https://github.com/riscv/riscv-gnu-toolchain

Create a directory in /opt

mkdir /opt/riscv

Configure and make

./configure --prefix=/opt/riscv
make linux

This might take several hours depending on your machine configuration. The tool will be available in /opt/riscv/bin.

Add /opt/riscv/bin to PATH

Open ~/.bashrc:

sudo gedit ~/.bashrc

Add near the end of the file and save:

export PATH="$PATH:/opt/riscv/bin"

Now the RISC-V tools will be available without specifying the path.