[Reprint] - Install Arm GNU Toolchain on Ubuntu 22.04

Install Arm GNU Toolchain on Ubuntu 22.04

  •  January 16, 2022 (November 14, 2023)

The Arm GNU toolchain (previously known as GNU Arm Embedded toolchain) is a collection of packages such as GCC (GNU Compiler Collection), Binutils, GDB, and other. It is used for embedded systems software development. This toolchain targets the 32-bit ARM Cortex-A, ARM Cortex-M, and ARN Cortex-R processor families.

This tutorial shows how to install Arm GNU toolchain on Ubuntu 22.04.

Install toolchain

There is no straightforward way to determine the latest version of toolchain via command line. So download web page and extract the latest version of toolchain as follows:

ARM_TOOLCHAIN_VERSION=$(curl -s https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads | grep -Po '<h4>Version \K.+(?=</h4>)')
 

Next, download archive file from official website:

curl -Lo gcc-arm-none-eabi.tar.xz "https://developer.arm.com/-/media/Files/downloads/gnu/${ARM_TOOLCHAIN_VERSION}/binrel/arm-gnu-toolchain-${ARM_TOOLCHAIN_VERSION}-x86_64-arm-none-eabi.tar.xz"
 

Create a new directory to store toolchain files:

sudo mkdir /opt/gcc-arm-none-eabi
 

Extract toolchain files to specified directory:

sudo tar xf gcc-arm-none-eabi.tar.xz --strip-components=1 -C /opt/gcc-arm-none-eabi
 

Add /opt/gcc-arm-none-eabi/bin directory to the PATH environment variable.

echo 'export PATH=$PATH:/opt/gcc-arm-none-eabi/bin' | sudo tee -a /etc/profile.d/gcc-arm-none-eabi.sh
 

To make changes to take effect, logout and login to your system or run the following command to apply the changes immediately:

source /etc/profile
 

We can check version of compilers:

arm-none-eabi-gcc --version
 
arm-none-eabi-g++ --version
 

Remove unnecessary archive file:

rm -rf gcc-arm-none-eabi.tar.xz
 

Testing toolchain

Create a main.c file:

nano main.c
 

Add the following code:

#include <stdio.h> int main() { printf("Hello world\n"); return 0; }

Compile a code:

arm-none-eabi-gcc --specs=rdimon.specs main.c -o test
 

The file command can be used to verify that executable file is for ARM architecture.

file test
 

Output:

test: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, with debug_info, not stripped

Uninstall toolchain

If you want to completely remove GNU Arm Embedded toolchain, delete the installation directory:

sudo rm -rf /opt/gcc-arm-none-eabi
 

Remove gcc-arm-none-eabi.sh file that is used to set environment variable:

sudo rm -rf /etc/profile.d/gcc-arm-none-eabi.sh
 

GNU Debugger (GDB) dependencies

Read this section if you want to use GNU Debugger (GDB). It requires installing additional dependencies.

  • If you are receiving an error about missing libncursesw.so.5 library:
arm-none-eabi-gdb: error while loading shared libraries: libncursesw.so.5: cannot open shared object file: No such file or directory

Then install libncursesw5 package:

sudo apt install -y libncursesw5
 
  • On Linux, Arm GNU toolchain provides GDB with Python support. It requires installation of Python 3.8. If you are receiving an error regarding Python, such as:
Could not find platform independent libraries <prefix> Could not find platform dependent libraries <exec_prefix> Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] Python path configuration: PYTHONHOME = (not set) PYTHONPATH = (not set) ... Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding Python runtime state: core initialized ModuleNotFoundError: No module named 'encodings'

Then install Python 3.8 using the separate post. See section "Install older versions".

When installation finished, check GDB version:

arm-none-eabi-gdb --version
 

If everything installed successfully, you will get output similar to the following:

GNU gdb (Arm GNU Toolchain 12.2.MPACBTI-Bet1 (Build arm-12-mpacbti.16)) 13.0.50.20220406-git Copyright (C) 2022 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.

posted on 2025-09-29 14:25  ENGINEER-F  阅读(17)  评论(1)    收藏  举报