In this tutorial you will learn how to install ROS2 Foxy Fitzroy on Raspberry Pi 4.
ROS2 is a great framework/middleware for robotics applications. With a Raspberry Pi board you can go much further, and embed a complete ROS2 application inside a small robot.
For example, if you want to build a mobile base with wheels and a camera, well a Raspberry Pi 4 will be perfect for that. You can then create a network of robots all connected together.
Which Raspberry Pi 4 version for ROS2 (RAM specs)
As you may know, the Raspberry Pi 4 board comes with different possible hardware configurations. You can choose between 2, 4 or even 8GB of RAM (previously also 1GB but discontinued).
If you currently have the 1GB version: 1 GB for Ubuntu Server + ROS2 is enough, but you’ll probably be limited in the future if you try to start more than a few nodes and launch files. If you want to avoid doing some optimization because of the RAM, I suggest you go with the 2GB (or more) version of the board.
After 2GB, then it’s quite simple: more RAM means more expensive. For starting and prototyping with ROS2, 2GB should be enough.
You are learning ROS2...
As a complete beginner? Check out ROS2 For Beginners and learn ROS2 in 1 week.
As a ROS1 developer? Check out Learn ROS2 as a ROS1 Developer and Migrate Your ROS Projects.
And one thing to keep in mind when using ROS2 on a Raspberry Pi: the Pi is certainly not as powerful as your computer/laptop, so you won’t be able to do 100% of what you do in your laptop, and some heavy features might run slower.
Prerequisites: install Ubuntu Server 20.04
First you will need to install Ubuntu Server 20.04 on your Raspberry Pi 4.
We’ll use Ubuntu Server here because it’s probably the best suited OS for ROS2 on Raspberry Pi. ROS2 is really easy to install and works well on Ubuntu. For this tutorial you won’t need a desktop with Ubuntu on your Pi.
Also, as we’ll install ROS2 Foxy, make sure you have the version 20.04 for Ubuntu, since each version of ROS2 is only compatible with one Ubuntu version.
Once everything is setup and you have an Internet connection + ssh access to your Pi, you can start installing ROS2.
Install ROS2 on Ubuntu on Raspberry Pi 4
Make sure to execute the commands in the order.
sudo apt update && sudo apt install locales sudo locale-gen en_US en_US.UTF-8 sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 export LANG=en_US.UTF-8
sudo apt update && sudo apt install curl gnupg2 lsb-release sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(source /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
Install ROS2 core packages
Now that you have added the ROS2 repository to your sources list, update.
sudo apt update
And now you can install ROS2.
Important: here we won’t install ros-foxy-desktop, we’ll install ros-foxy-ros-base, which contains no GUI tools, just the bare minimum you need to write and execute your ROS2 programs.
sudo apt install ros-foxy-ros-base
The ros-foxy-ros-base package is in fact a collection of many other packages, so the list of stuff to install will be pretty big. This step may take a few minutes to complete.
Install colcon (build tool)
After you’ll write some ROS2 code into your own packages, you’ll need to build those packages.
ROS2 uses colcon as a build tool (and ament as the build system). When you only install the ROS2 core packages, colcon is not here, so install it manually.
sudo apt install python3-colcon-common-extensions
Auto-completion for ROS2 command line tools
ROS2 comes with a lot of useful command line tools, and if you want to be able to use auto-completion for those tools, you’ll need to install The argcomplete Python module. First make sure you have pip3 installed.
sudo apt install python3-pip pip3 install argcomplete
Setup your environment for ROS2
Great, ROS2 Foxy is now installed on your Raspberry Pi 4 with Ubuntu Server 20.04!
Now, in order to actually use ROS2, you’ll need to setup your environment every time you open a new session (terminal). To source your ROS2 installation in your environment, run
And because it won’t be that practical to do this for every new session you open, add this line to your bashrc.
echo "source /opt/ros/foxy/setup.bash" >> ~/.bashrc
So, from now on, every time you open a terminal, your bashrc will be executed and your environment will be ready for ROS2.
A few tips on how to best use ROS2 on Raspberry Pi
As you saw during the installation, we didn’t install any GUI tool, just the minimum to get things running.
If you need to use some visualization tools, such as Rviz or Gazebo, or if you need to do some heavy processing, then you might use a multi-machine setup with your Pi (or multiple Pis) and a more powerful computer/laptop. It’s very easy to make multiple machines communicate between each other with ROS2. You can run the programs that control hardware on your Raspberry Pi, and then exchange data – through ROS2 communication features – with your laptop, which will handle any GUI or heavy processing tasks.
Also, as you’ve only installed the core base, you might sometimes have to install additional packages.
To install a new ROS2 package, it’s quite easy: the name of the package will be “ros-distribution-package-name”. So if you want to install, on ROS2 Foxy, the example-interfaces package (which contains message and service definitions you can use when you get started with ROS2), you will run
sudo apt install ros-foxy-example-interfaces.
Start learning ROS2 with Raspberry Pi 4
If you’re new to ROS2, then you can continue with those tutorials:
Whether you’re learning ROS2 on a laptop, or on a Raspberry Pi, all the beginners tutorials are valid.
Also, if you want to learn much quicker and with a complete step-by-step method, check out this ROS2 for Beginners course.