Skip to main content

How to install the xPack GNU RISC-V Embedded GCC

GitHub package.json version GitHub release (latest by date) GitHub Release Date npm (scoped) GitHub Downloads (all assets, all releases) npm

The xPack GNU RISC-V Embedded GCC can be installed automatically, using the xpm command (the recommended method), or manually, by downloading and unpacking one of the platform specific archives.

Automated install

The easiest (and recommended) way to install GNU RISC-V Embedded GCC is via xpm and the package available as @xpack-dev-tools/riscv-none-elf-gcc from the npmjs.com registry.

xPacks refresher

xPacks (short for xpm packages) are general-purpose, language-neutral software packages. They use the same format as npm packages, which is a collection of files/folders and a package.json file with the package metadata.

Binary xPacks also include references to regular archives with the platform specific binaries (such as .tar.gz for Unix or .zip for Windows). These archives are unpacked and links/forwarders to the executables are created in a .bin folder.

For more details, please see the previous explanation in the Getting Started page.

Prerequisites

The only requirement for an automated install is a recent xpm, which is a portable Node.js command line application that complements npm with several extra features specific to C/C++ projects.

To install xpm, follow the instructions in the xpm install page.

If already installed, it is always a good idea to update it to the latest version with:

npm install --location=global xpm@latest
tip

Although not mandated by xpm, it is also a good idea to upgrade npm to the latest version, and node to a reasonably recent version (currently npm requires a node >=18.17.0).

Local installs

One of the xPack design goals is to allow each project to choose the exact versions of the tools it requires.

Similarly to npm being able to install specific versions of the JavaScript tools into each project, xpm was also designed to be able to install specific versions of the required binary tools locally into each project.

Therefore, similarly to the way npm installs the JavaScript packages into node_modules, xpm installs the binary tools into xpacks. Here there will be separate folders with the installed packages, for example xpacks/@xpack-dev-tools/riscv-none-elf-gcc.

Each such folder includes the package.json file with the project metadata and a sub-folder .content with the extracted binary archive. The executables are usually in .content/bin.

tip

On some platforms, names starting with . (dot) might be hidden for normal browsing, and seeing them requires separate options (like ls -A) or, in file browsers, to enable settings like Show Hidden Files.

The xpacks/.bin folder

If multiple binary packages are installed, in order to allow the executables to be accessed, one possible solution is to add all <package>/.content/bin folders to the PATH.

To simplify things, npm employs a separate <project>/node_modules/.bin folder where it places links/forwarders pointing to the actual executable files.

Similarly, xpm adds links/forwarders into a separate <project>/xpacks/.bin folder.

With this setup, the project needs to prepend only this .bin folder to the PATH, and all the required tools are accesible and prefered to possible system tools.

Global installs and the user global xPacks store

Given that some binary tools (such as toolchains) can be very large (hundreds of megabytes or more), it is impractical to keep multiple copies of these tools, one for each project.

Instead, xpm installs the binary packages only once into a user global store (a platform-dependent folder within the home folder), thereby conserving disk space when the same tools are used across multiple projects.

In order to allow the projects to access the binary tools installed in the user global store, instead of unpacking the archives in xpacks, xpm adds symbolic links pointing to the user global xPacks store.

The outcome is functionally equivalent to installing the tools into each project, but without the wasted disk space.

tip

It is possible to force a local install into a project by passing --copy to xpm install.

if necessary, it is also possible to install packages only globally, without creating local links/forwarders (see below).

The user xPacks cache

To save download time, all archives are first stored in a cache, and all subsequent downloads are replaced with the cached content.

Therefore all published archives should be read-only and it is not allowed to replace them at a later time.

Initialise the project

Upon initial use, ensure that a package.json file is present in the project root folder.

This can be achieved by running xpm init in the desired project folder (substitute my-project accordingly):

cd my-project
xpm init
Under the hood

The main purpose of xpm init is to create a package.json file, if not already present.

In addition to name & version, the minimal package.json must include a property named xpacks, even empty. This property is mandatory to identify the package as an xpm package.

Install into the project

The next step is to install the riscv-none-elf-gcc package into the project:

xpm install @xpack-dev-tools/riscv-none-elf-gcc@latest --verbose

This command will install the latest available version.

To install a specific version, mention it explicitly:

xpm install @xpack-dev-tools/riscv-none-elf-gcc@14.2.0-2.1 --verbose

The main result is a set of forwarders in the .bin folder:

dir xpacks\.bin
PATH setup

With all binary tools installed in xpacks/.bin, the project build configurations need only a single PATH adjustment:

export PATH=<...project-path...>/xpacks/.bin:$PATH
tip

This syntax is for the Git Bash console. When using COMMAND.EXE or Power Shell, adjust the syntax for the corresponding Windows specific shell.

Installation details

The above xpm install command will do the following:

  • identify the platform specific archive for the latest available version of GNU RISC-V Embedded GCC, download it into a cache and unpack it into a versioned folder in the user global xPacks store (if not already there); check the output of the xpm install command for the actual folder used on your platform;
  • create a local symbolic link like xpacks/@xpack-dev-tools/riscv-none-elf-gcc pointing to the versioned folder in the user global xPacks store
  • add links/forwarders into the local xpacks/.bin folder, referring to the binaries in xpacks/@xpack-dev-tools/riscv-none-elf-gcc/.content/bin;
  • add @xpack-dev-tools/riscv-none-elf-gcc to package.json as a development dependency; this associates a specific version of GNU RISC-V Embedded GCC with the current project (details below).
tip

The install location can be configured using the XPACKS_STORE_FOLDER environment variable; for more details please check the xpm folders page.

Reproducibility and devDependencies

To ensure reproducibility, it is essential for each project to always use the exact desired versions of the required tools, regardless of the tools installed in the system.

To achieve this goal, xpm records all locally installed binary packages as development dependencies in the project package.json file.

The result looks like this:

  "xpack": {
"minimumXpmRequired": "0.19.1",
"dependencies": {},
"devDependencies": {
"@xpack-dev-tools/riscv-none-elf-gcc": {
"specifier": "14.2.0-2.1",
"local": "link",
"platforms": "all"
}
},
"properties": {},
"actions": {},
"buildConfigurations": {}
}

If the package.json is saved in the revision system, the above definition acts as a hard reference to the specific version of xPack GNU RISC-V Embedded GCC.

After cloning the project into a different location, the command xpm install can be used to install all development dependencies.

This is particularly useful for CI/CD environments.

Install globally

For older development environments, it is also possible to install GNU RISC-V Embedded GCC only globally in the user global xPacks store, without any local links/forwarders; it is the developer's responsibility to configure the path to the tools.

No other files are installed in any system folders or other locations.

xpm install @xpack-dev-tools/riscv-none-elf-gcc@latest --global --verbose
note

Installing packages locally into a project always installs the packages in the user global xPacks store; subsequent attempts to install the packages globally will fail with already installed.

PATH setup

In order to access the GNU RISC-V Embedded GCC binaries installed in the user global xPacks store, the project build configurations need a PATH adjustment:

export PATH=$HOME/AppData/Roaming/xPacks/@pack-dev-tools/riscv-none-elf-gcc/14.2.0-2.1/.content/bin:$PATH
tip

When not using the Git console, adjust the syntax for the corresponding shell.

Uninstall

The binaries do not use any form of installer; instead they are distributed as portable .tar.gz archives; therefore they do not require to run any uninstaller; simply removing the links and possibly the user global xPacks store folder and the user xPack cache folder is enough.

To remove the symbolic links created by xpm in the current project, go to the project folder:

cd my-project

and ask xpm to uninstall the package:

xpm uninstall @xpack-dev-tools/riscv-none-elf-gcc --verbose

To completely remove the package from the user global xPacks store:

xpm uninstall --global @xpack-dev-tools/riscv-none-elf-gcc --verbose
Clean-ups

For a thorough clean-up, please note that xpm uses only two folders:

  • %APPDATA%\Roaming\xPacks
  • %APPDATA%\Local\Caches\xPacks

They can be removed at any time and space reclaimed; xpm will recreate them on new installs.

However, projects linking to the user global xPacks store will fail with broken paths.

Quick test

To check if the GNU RISC-V Embedded GCC installed by xpm starts properly, use something like:

C:\> %USERPROFILE%\AppData\Roaming\xPacks\@xpack-dev-tools\riscv-none-elf-gcc\14.2.0-2.1\.content\bin\riscv-none-elf-gcc.exe --version
riscv-none-elf-gcc (xPack GNU RISC-V Embedded GCC x86_64) 14.2.0
note

The reported version is the upstream version, which is shorter than the xPack version, as the latter requires more digits to identify the releases.

Manual install

For all platforms, the xPack GNU RISC-V Embedded GCC binaries are released as portable archives that can be installed in any location.

The archives can be downloaded from the GitHub Releases pages.

Download & unpack

The Windows versions of xPack GNU RISC-V Embedded GCC are packed as .zip files. Download the latest version named like:

  • xpack-riscv-none-elf-gcc-14.2.0-2-win32-x64.zip
note

In case you wonder where the suffix comes from, it is exactly the Node.js process.platform and process.arch. The win32 part is confusing, but we have to live with it.

To manually install the xPack GNU RISC-V Embedded GCC, unpack the archive and move it to a location of your choice.

The recommended location is the %USERPROFILE%\AppData\Roaming\xPacks\riscv-none-elf-gcc folder, for example C:\Users\ilg\AppData\Roaming\xPacks\riscv-none-elf-gcc\xpack-riscv-none-elf-gcc-14.2.0-2.

note

According to Microsoft, AppData\Roaming is the recommended location for installing user specific packages.

info

For manual installs, the recommended install location is slightly different then the folders created by xpm install, which use the @xpack-dev-tools scope to group different tools, and .content to store the unpacked archive.

Quick test

To check if the GNU RISC-V Embedded GCC installed manually starts properly, use something like:

C:\> %USERPROFILE%\AppData\Roaming\xPacks\riscv-none-elf-gcc\xpack-riscv-none-elf-gcc-14.2.0-2\bin\riscv-none-elf-gcc.exe --version
riscv-none-elf-gcc (xPack GNU RISC-V Embedded GCC x86_64) 14.2.0
note

The reported version is the upstream version, which is shorter than the xPack version, as the latter requires more digits to identify the releases.

Folders hierarchy

After install, the package creates a hierarchy of folders like the following (only the first two depth levels are shown):

C:> tree /f %USERPROFILE%\AppData\Roaming\xPacks\@xpack-dev-tools\riscv-none-elf-gcc\14.2.0-2.1\.content
Folder PATH listing
Volume serial number is B02D-925C
├── README.md
├── bin
│ ├── DLLs
│ ├── libgcc_s_seh-1.dll
│ ├── libgmp-10.dll
│ ├── libmpc-3.dll
│ ├── libmpfr-6.dll
│ ├── libstdc++-6.dll
│ ├── libwinpthread-1.dll
│ ├── libzstd.dll
│ ├── python312.dll
│ ├── python312.zip
│ ├── riscv-none-elf-addr2line.exe
│ ├── riscv-none-elf-ar.exe
│ ├── riscv-none-elf-as.exe
│ ├── riscv-none-elf-c++.exe
│ ├── riscv-none-elf-c++filt.exe
│ ├── riscv-none-elf-cpp.exe
│ ├── riscv-none-elf-elfedit.exe
│ ├── riscv-none-elf-g++.exe
│ ├── riscv-none-elf-gcc-14.2.0.exe
│ ├── riscv-none-elf-gcc-ar.exe
│ ├── riscv-none-elf-gcc-nm.exe
│ ├── riscv-none-elf-gcc-ranlib.exe
│ ├── riscv-none-elf-gcc.exe
│ ├── riscv-none-elf-gcov-dump.exe
│ ├── riscv-none-elf-gcov-tool.exe
│ ├── riscv-none-elf-gcov.exe
│ ├── riscv-none-elf-gdb-add-index
│ ├── riscv-none-elf-gdb-add-index-py3
│ ├── riscv-none-elf-gdb-py3.exe
│ ├── riscv-none-elf-gdb.exe
│ ├── riscv-none-elf-gfortran.exe
│ ├── riscv-none-elf-gprof.exe
│ ├── riscv-none-elf-ld.bfd.exe
│ ├── riscv-none-elf-ld.exe
│ ├── riscv-none-elf-lto-dump.exe
│ ├── riscv-none-elf-nm.exe
│ ├── riscv-none-elf-objcopy.exe
│ ├── riscv-none-elf-objdump.exe
│ ├── riscv-none-elf-ranlib.exe
│ ├── riscv-none-elf-readelf.exe
│ ├── riscv-none-elf-size.exe
│ ├── riscv-none-elf-strings.exe
│ └── riscv-none-elf-strip.exe
├── distro-info
│ └── licenses
├── include
│ ├── curses.h
│ ├── cursesapp.h
│ ├── cursesf.h
│ ├── cursesm.h
│ ├── cursesp.h
│ ├── cursesw.h
│ ├── cursslk.h
│ ├── eti.h
│ ├── etip.h
│ ├── form.h
│ ├── gdb
│ ├── gmp.h
│ ├── gmpxx.h
│ ├── iconv.h
│ ├── isl
│ ├── libcharset.h
│ ├── localcharset.h
│ ├── lzma
│ ├── lzma.h
│ ├── menu.h
│ ├── mpc.h
│ ├── mpf2mpfr.h
│ ├── mpfr.h
│ ├── ncurses_dll.h
│ ├── panel.h
│ ├── term.h
│ ├── term_entry.h
│ ├── termcap.h
│ ├── unctrl.h
│ ├── zconf.h
│ ├── zdict.h
│ ├── zlib.h
│ ├── zstd.h
│ └── zstd_errors.h
├── lib
│ ├── bfd-plugins
│ ├── cmake
│ ├── gcc
│ ├── libcharset.a
│ ├── libform.a
│ ├── libgmp.a
│ ├── libgmpxx.a
│ ├── libiconv.a
│ ├── libisl.a
│ ├── libisl.so.23.3.0-gdb.py
│ ├── liblzma.a
│ ├── libmenu.a
│ ├── libmpc.a
│ ├── libmpfr.a
│ ├── libncurses++.a
│ ├── libncurses.a
│ ├── libpanel.a
│ ├── libz.a
│ ├── libzstd.a
│ ├── libzstd.so.1.5.6
│ ├── pkgconfig
│ └── texinfo
├── libexec
│ └── gcc
├── riscv-none-elf
│ ├── bin
│ ├── include
│ ├── lib
│ └── share
└── share
├── doc
├── gcc-14.2.0
├── info
├── man
└── texinfo

27 directories, 91 files