Install ROS on Raspberry Pi 4B

This post covers getting ROS Melodic up and running on Raspberry Pi 4B using the Ubuntu 18.04 (Bionic) distribution of Linux.

To begin the install of ROS on Raspberry Pi 4B, we need to consider: which version of ROS should we use?

To answer this question, we could consider several factors:

  • most recent available?
  • best supported / documented in the community?
  • most well-tried and tested?
  • supports the hardware?

We also must take into consideration the Ubuntu version.

A quick review of the Ubuntu distros available for Pi 4B, shows that Ubuntu 19.02 is the officially supported version. However, the corresponding ROS version (for that version of Ubuntu) is not yet available from Open Robotics, the creators of ROS.

ROS distributions let developers work against a relatively stable codebase, and the ROS Wiki shows the ROS Melodic distro is targeted at the Ubuntu 18.04 (Bionic) release. For more details of which ROS releases inter-operate with which OS release, see:

Given the above considerations, Ubuntu 18.04 LTS is the best choice. Note the chain of dependency from hardware to OS to ROS version. Use of the Pi 4 results in the selection of a particular Ubuntu release (18.04), which then implies ROS Melodic.

Pre-built images for Ubuntu and ROS

To keep things simple and minimize effort, it’s preferable to use pre-built images for the ROS and Ubuntu distros (if available). This avoids the need to build ROS or Linux from source, but also raises a couple of questions:

  • 32-bit or 64-bit?
  • which official / unofficial image?

A quick search suggests it would be best to choose a 64-bit image for maximum performance and the ability to access all 4 GB of memory (if you have it!). More about this later.

The table below (shamelessly copied from list the Platforms/Architecture combination for which there are ROS install binary packages available.

Ubuntu Artful Ubuntu Bionic Debian Stretch
x86_64 X X X
armhf X
arm64 X X

As can be seen, the ROS distro for Ubuntu Bionic supports arm64! This means that we can use a ROS binary on a 64-bit OS image to install ROS on Raspberry Pi 4B.

Need to update the on-board firmware

As of Raspberry Pi 4, we now have additional boot code considerations. On Pi 4 the boot firmware is stored on a separate EEPROM chip, not the SD card.

As of Raspberry Pi 4, we now have additional boot code considerations. On Pi 4 the boot firmware is stored on a separate EEPROM chip, not the SD card.

The boot firmware that ships with a new Pi 4 will not contain the latest code, because boards ship with the initial release of the firmware installed, which then gets revised later. Consequently, it is highly recommended, well, mandatory really, to update the firmware. See…

Unfortunately, we must boot from Raspbian (the Linux distro from the Raspberry Pi Foundation) not Ubuntu, in order to update the firmware! That sucks potatoes, but it is what it is.

Create Raspbian SD card

So the first step towards updating the boot firmware is to create an SD card with Raspbian installed. Fret not, the process is simple and reliable. Get the zip file from:

Insert the SD card into a linux PC and create Raspbian SD card using the following command:

sudo unzip -p /home/jjordan/tmp/ | sudo dd of=/dev/sdb bs=4M conv=fsync

If you’re not sure what to do here, or run into difficulties, you could refer to for some additional information.

After the above command completes, remove the card from the PC and re-insert it into your Pi 4. Power up your pi 4, and it should boot into Raspbian OS!

Update the firmware

To update the firmware, boot with Raspbian SD card and the Pi 4 connected to a TV/monitor, keyboard and ethernet connection with access to the internet. The default login credentials for Raspbian are:

login: pi
password: raspberry

For more complete details of updating the firmware, see…

I’ll summarize the steps here. Using the keyboard and monitor attached to the Pi 4, manually type in the following commands:

sudo apt-get update && sudo apt-get dist-upgrade -y

sudo rpi-update

sudo rpi-eeprom-update -a

That’s it!

Create the 64-bit Ubuntu SD card

Now that we’ve gotten the work of updating the firmware out of the way, we’re free to move forward with getting Ubuntu installed. We’re going to do this on a separate SD card, as we would like to keep our Raspbian OS for any future firmware updates.

Begin by getting the unofficial Ubuntu image from:

If you run into a problem with the ‘.xz’ file, you may need to unzip it and re-zip it to ‘.zip’ file format. I had to do this because my ancient Samsung laptop that I use for low-level tasks like burning SD cards does not understand ‘.xz’ files (nor will it ever!)

Having downloaded the Ubuntu binary image, we then burn it to the SD card:

sudo unzip -p /home/jjordan/tmp/ | sudo dd of=/dev/sdb bs=4M conv=fsync

Transfer the SD card to the Pi 4 and it should boot into Ubuntu!… But, no WiFi yet, of course!

Bring up WiFi

In more recent incarnations of Ubuntu, the way WiFi is configured has changed. If you’re going from Ubuntu 16.04 to 18.04, you will need to get on-board (forgive the pun) with this new method. Not to worry, it’s really simple.

For an overview of this method, known as “netplan”, here’s a good reference:

To setup the Pi 4 WiFi, we simply edit the following file:

ubuntu@ubuntu:~$ cat /etc/netplan/50-cloud-init.yaml

# This file is generated from information provided by
# the datasource.  Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
            dhcp4: true
                macaddress: dc:a6:32:27:8e:41
            set-name: eth0
    version: 2

            dhcp4: yes
            dhcp6: no
                    password: xxx

Ignore the confusing comment about changes not persisting across an instance. It’s not relevant to our situation. Just set the WiFi SSID and password, then reboot. The above example shows how to change the file given the following:

password: xxx

Simply change to above to suit whatever your WiFi credentials happen to be.

Reboot your Pi 4. WiFi is up!

Install ROS on Raspberry Pi 4B

We’re finally ready to Install ROS on Raspberry Pi 4B! For more complete information, see…

Here’s the quick summary of the steps:

sudo sh -c ‘echo “deb $(lsb_release -sc) main” > /etc/apt/sources.list.d/ros-latest.list’

sudo apt-key adv –keyserver ‘hkp://’ –recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

sudo apt update

Deviating from my previous installs (Indigo and Kinetic, where I used ‘sudo apt-get install ros-kinetic-robot’):

sudo apt install ros-melodic-ros-base

sudo rosdep init
rosdep update

echo “source /opt/ros/melodic/setup.bash” >> ~/.bashrc
source ~/.bashrc

sudo apt install python-rosinstall python-rosinstall-generator python-wstool build-essential

sudo apt install ros-melodic-slam-gmapping
sudo apt install ros-melodic-navigation

Update (07/03/2020):

On running hector mapping, I had the following problem:

ERROR: cannot launch node of type [joint_state_publisher/joint_state_publisher]: joint_state_publisher

The above is no doubt because I did a ‘base’ install, not a ‘robot’ install!

sudo apt install ros-melodic-robot

… after which, it’s working fine.

That’s all. We’re done!