# How To Install ROS2 Jazzy Base On Raspberry Pi 4 or 5 (FULL INSTALL)

<figure><img src="https://1813945869-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvaPba1OWKgmXxFGX8DOE%2Fuploads%2Fzuu01iLgFKUKTVRzlGHn%2Fjazzy-pi-install.jpg?alt=media&#x26;token=3e299622-f405-4d1b-bc50-67281f94ac69" alt=""><figcaption></figcaption></figure>

If you'll be building intelligent robotics applications, chances are you’ll want the power of ROS2 running on a compact, efficient platform like the Raspberry Pi. This guide walks you through the complete process of setting up **ROS2 Jazzy Base** on on a **Raspberry Pi 4 or 5** running **Ubuntu 24.04 Server** — from the initial installation to configuring essential tools like colcon and rosdep. By the end, you'll be ready to develop and deploy robust robotics applications on this versatile microcomputer.

Let’s dive in and get your Pi humming with ROS2!

{% hint style="info" %}
NOTE: This tutorial is based on the official ROS Jazzy Documentation [here](https://docs.ros.org/en/jazzy/Installation/Ubuntu-Install-Debs.html)
{% endhint %}

### Prerequisite

* First ensure you have the Ubuntu 24.04 LTS server installed on the Raspberry Pi 4 or 5 (2GB, 4GB, or 8GB. The higher, the better)
* Also, if you did headless installation, you should be able to communicate with the Pi from your Dev PC (also running Ubuntu 24.04 LTS) via SSH.&#x20;

{% hint style="info" %}
All we'll be doing in this tutorial assumes you are able to communicate with your Raspberry Pi 4 or 5 running Ubuntu 24.04 LTS server with SSH
{% endhint %}

<figure><img src="https://1813945869-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvaPba1OWKgmXxFGX8DOE%2Fuploads%2FpgcRawz7svprpCilTfoh%2Fpc-pi-ssh-comm.png?alt=media&#x26;token=c73ae09a-1197-4aa2-8db4-55523e5556ce" alt=""><figcaption></figcaption></figure>

### Installing ROS Jazzy Base

Follow the instructions (step by step) to install ros-jazzy-ros-base (not desktop) on your Raspberry Pi running Ubuntu 24.04 LTS server.

* Set locale<br>

  ```shellscript
  locale  # check for UTF-8
  ```

  ```shellscript
  sudo apt update && sudo apt install locales
  ```

  ```shellscript
  sudo locale-gen en_US en_US.UTF-8
  ```

  ```shellscript
  sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
  ```

  ```shellscript
  export LANG=en_US.UTF-8
  ```

  ```shellscript
  locale  # verify settings
  ```

* Setup sources and required repositories<br>

  ```shellscript
  sudo apt install software-properties-common
  ```

  ```shellscript
  sudo add-apt-repository universe
  ```

  ```shellscript
  sudo apt update && sudo apt install curl -y
  ```

  ```shellscript
  export ROS_APT_SOURCE_VERSION=$(curl -s https://api.github.com/repos/ros-infrastructure/ros-apt-source/releases/latest | grep -F "tag_name" | awk -F\" '{print $4}')
  ```

  ```shellscript
  curl -L -o /tmp/ros2-apt-source.deb "https://github.com/ros-infrastructure/ros-apt-source/releases/download/${ROS_APT_SOURCE_VERSION}/ros2-apt-source_${ROS_APT_SOURCE_VERSION}.$(. /etc/os-release && echo ${UBUNTU_CODENAME:-${VERSION_CODENAME}})_all.deb"
  ```

  ```shellscript
  sudo dpkg -i /tmp/ros2-apt-source.deb
  ```

* Install all the necessary ROS2 development tools - **rosdep**, **colcon**, **vcs-tool**, etc.

  ```sh
  sudo apt update && sudo apt install ros-dev-tools
  ```

* Install ros-jazzy-ros-base (Bare Bones): Communication libraries, message packages, command line tools. No GUI tools.

  ```shellscript
  sudo apt update && sudo apt upgrade
  ```

  ```sh
  sudo apt install ros-jazzy-ros-base
  ```

* Source the ros jazzy environment with this command<br>

  ```sh
  source /opt/ros/jazzy/setup.bash
  ```

### Add ROS Setup File To .bashrc For Auto Sourcing

```shellscript
echo "source /opt/ros/jazzy/setup.bash" >> ~/.bashrc
```

Now the ros jazzy environment setup file will be automatically sourced whenever you open a new terminal.&#x20;

### Setting up colcon for Building ROS2 packages

**colcon** is a build tool required to build your ROS2 packages created in your ros workspace. You have already installed it when you ran the `sudo apt install ros-dev-tools` command previously.\
But we need to set it up for things like tab completion, etc. during builds. Run the following command in your terminal.

* Setup colcon\_cd<br>

  ```shellscript
  echo "source /usr/share/colcon_cd/function/colcon_cd.sh" >> ~/.bashrc
  ```

  ```shellscript
  echo "export _colcon_cd_root=/opt/ros/jazzy/" >> ~/.bashrc
  ```

* Setup colcon tab completion<br>

  ```sh
  echo "source /usr/share/colcon_argcomplete/hook/colcon-argcomplete.bash" >> ~/.bashrc
  ```

With all the above added to the `.bashrc` file, the colcon environment and functions will be automatically activated whenever you open a new terminal as well as automatic sourcing of the ros-humble environment.

{% hint style="info" %}
To learn more about colcon check the link to its documentation [here](https://docs.ros.org/en/jazzy/Tutorials/Beginner-Client-Libraries/Colcon-Tutorial.html)
{% endhint %}

you should see the following highlighted text (in the image below) at the bottom of your `.bashrc` file.  Run this command:&#x20;

```shellscript
sudo nano ~/.bashrc
```

<figure><img src="https://1813945869-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvaPba1OWKgmXxFGX8DOE%2Fuploads%2FNeMM0BQ6Uf8HqgAs3OTl%2Fjazzy-bash.png?alt=media&#x26;token=fe356c05-4d14-466a-a075-d66d34322440" alt=""><figcaption></figcaption></figure>

### Intialize and Update rosdep

rosdep is a dependency management utility that can work with packages and external libraries. It is a command line utility for identifying and installing dependencies to build or install a package.

It is most often invoked before before building a package with colcon. It will basiclally download and installing the necessary dependencies a specified in the `package.xml`file so you don't have to manually install each dependencies again.

**rosdep** was already installed when you ran the `sudo apt install ros-dev-tools` command previously.

{% hint style="info" %}
To learn more about rosdep check out its documentation [here](https://docs.ros.org/en/jazzy/Tutorials/Intermediate/Rosdep.html)
{% endhint %}

Follow the instructions below to instialize and update rosdep:

```shellscript
sudo apt update
```

```shellscript
sudo rosdep init
```

```shellscript
rosdep update
```

### Optional (Install Cyclone DDS)

If you would be using ROS2 for navigation and some other high speed data transfer, install and use the **Cyclone DDS** in place of the default **Fast DDS.**

```shellscript
sudo apt install ros-jazzy-rmw-cyclonedds-cpp
```

```shellscript
export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp
```

```shellscript
echo "export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp" >> ~/.bashrc
```

***

### Creating A ROS2 Workspace

***

<figure><img src="https://1813945869-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvaPba1OWKgmXxFGX8DOE%2Fuploads%2FpgcRawz7svprpCilTfoh%2Fpc-pi-ssh-comm.png?alt=media&#x26;token=c73ae09a-1197-4aa2-8db4-55523e5556ce" alt=""><figcaption></figcaption></figure>

* In the root folder of your Raspberry Pi (i.e the home directory), create a **ros workspace** folder. I would be using this workspace name - `ros-ws`.<br>

  ```sh
  mkdir -p ~/ros-ws/src
  ```

* change directory into the root **ros workspace** folder

  ```sh
  cd ~/ros-ws
  ```

* build the **ros workspace** initially with colcon (while still in the root workspace folder)

  ```sh
  colcon build
  ```

  \
  you should now see three other folders - **build**, **install**, and **log** - apart from the **src** folder already created earlier. Run `ls`  to see them in terminal

* Let's setup automatic sourcing for the created workspace - `ros-ws`- in the `.bashrc` file so that it is automatically sourced whenever you open a new terminal. Run this in terminal:

  ```sh
  echo "source ~/ros-ws/install/setup.bash" >> ~/.bashrc
  ```

### Test  with helloworld package

* Open a new terminal (to auto source your ros2 environment and workspace) and cd into your ros workspace's **src** folder

  ```sh
  cd ~/ros-ws/src
  ```

* Clone this [**helloworld\_ros2**](https://github.com/samuko-things/helloworld_ros2) package in the src folder

  ```sh
  git clone https://github.com/samuko-things/helloworld_ros2.git
  ```

* Change directory into the root **ros workspace** folder<br>

  ```sh
  cd ~/ros-ws
  ```

* Optionally, run rosdep to install the neccessary package dependencies specified in the package's `package.xml`file<br>

  ```sh
  rosdep install -i --from-path src --rosdistro jazzy -y
  ```

* Build the package with colcon<br>

  ```sh
  colcon build --symlink-install
  ```

* Open two seperate terminals. In one of the terminals, run the c++ talker node:<br>

  ```sh
  ros2 run helloworld_cpp talker
  ```

* In the other terminal, run a python listener node:<br>

  ```sh
  ros2 run helloworld_py listener

  ```

{% hint style="info" %}
**FINALLY:** you can also setup and build the **helloworld\_ros2** package in your **DEV PC** then run talker and listener in the **DEV PC** and **RASPBERRY PI** respectively to see if both communicates with each other via ROS2
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://robocre8.gitbook.io/robocre8/tutorials/how-to-install-ros2-jazzy-base-on-raspberry-pi-4-or-5-full-install.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
