The Easiest way to install ROS Melodic on RaspberryPi 4

In this blog, we shall install ROS Melodic on Raspberry Pi 4 in a hassle-free way. But, before that make sure you have the raspberry pi OS up and ready, connected to the internet. Ok then, let’s GET STARTED!

Let’s start by setting up the repositories and installing the necessary dependencies :

  • Setting up the repositories
sudo sh -c 'echo "deb $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
  • Add the KEY
sudo apt-key adv --keyserver 'hkp://' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
  • Update && Upgrade
sudo apt-get update && sudo apt-get upgrade
  • Installing the required dependence
sudo apt-get install -y python-rosdep python-rosinstall-generator python-wstool python-rosinstall build-essential  cmake
  • Then initialize rosdep and update it
sudo rosdep init sudo rosdep update

As we need to install ROS from Source we shall create a separate WorkSpace for it:

mkdir ~/ros_catkin_ws cd ~/ros_catkin_ws
  • Now, we shall install ROS Melodic
rosinstall_generator desktop --rosdistro melodic --deps --wet-only --tar > melodic-desktop-wet.rosinstall
  • This command will take some time depending on your Internet speed as its downloading all the core ROS package’s
wstool init -j8 src melodic-desktop-wet.rosinstall
  • [OPTIONAL] Run this command if the ‘wstool init’ is failed or interrupted by any cause
wstool update -j 4 -t src

Next, we use the rosdep tool for installing all the rest of the dependencies:

rosdep update cd ~/ros_catkin_ws rosdep install --from-paths src --ignore-src --rosdistro melodic -y

Finally, Build and Source the Installation

  • This command will take a lot of time so grab some snacks while it is downloading and resolving the dependencies
sudo ./src/catkin/bin/catkin_make_isolated --install -DCMAKE_BUILD_TYPE=Release --install-space /opt/ros/melodic -j2
  • Now ROS Melodic should be installed on your Raspberry Pi 4. We’ll source the new installation with the following command:
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc

So it's Done! Try launching roscore to check if everything is up and running

Setting things up for further use

  • Now, we shall create a separate workspace where we can install pkg’s and get started with using ROS Melodic
mkdir -p ~/catkin_ws/srccd ~/catkin_wscatkin_makeecho "source $HOME/catkin_ws/devel/setup.bash" >> ~/.bashrc

Now, you’re all set to use ROS Melodic with Pi 4. You can now install packages in your src directory and get started!

Hit the ‘Clap’ if it helped you. Comment if uyou have doubts or want to start a discussion. Cheers!!



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store