Install ROS 2 Foxy alongside ROS Noetic on Ubuntu 20.04

By Melody Jindan Huang, PathOn.ai Research Scientist InternAugust 5, 2025

If you're starting your journey in robotics, chances are you'll need to work with both ROS (Robot Operating System) and ROS 2. In this guide, I'll walk you through installing ROS 2 Foxy, the LTS version compatible with Ubuntu 20.04, without affecting your existing ROS 1 (Noetic) setup.

🧰 Prerequisites

  • A laptop or PC with Ubuntu 20.04 + ROS Noetic installed and working
  • Some familiarity with using the terminal
  • A system with at least 5 GB of free disk space

🦊 Step 1: Set Locale, Add ROS 2 Foxy Sources and Keys

You may have already added the ROS 1 apt source, but ROS 2 uses the same base key and repo, just ensure it's up to date. Here are the steps:

1.1 Set Locale

Make sure you have a locale which supports UTF-8:

locale # check for UTF-8

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

locale # verify settings

1.2 Enable Universe Repository

Ensure that the Ubuntu Universe repository is enabled:

sudo apt install software-properties-common
sudo add-apt-repository universe

1.3 Add ROS Keyring

Add the ROS keyring:

sudo apt update && sudo apt install curl -y
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg

1.4 Add ROS 2 Apt Source

Then add the ROS 2 apt source:

echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null

1.5 Update Package Index

Finally, update package index:

sudo apt update
sudo apt upgrade

📦 Step 2: Install ROS 2 Foxy Desktop

sudo apt install ros-foxy-desktop python3-argcomplete

This will install the full Foxy release with core tools, RViz2, navigation, etc. You can find detailed instructions from: ROS 2 Foxy Installation Guide and ROS 2 Environment Configuration.

⚙️ Step 3: Source ROS 2 Foxy Separately

⚠️ Important:

You must not source both ROS Noetic and ROS 2 Foxy in the same terminal. Their environment variables conflict and will cause unexpected behavior.

To keep things clean and manageable, we'll create a dedicated environment script for ROS 2 Foxy. This allows you to switch between ROS 1 and ROS 2 easily by sourcing a different script in each terminal.

🧙 Create a ROS 2 Environment Script

Create and open a new script file for your ROS 2 environment setup:

touch ~/.ros2_env.sh
nano ~/.ros2_env.sh

Add the following content to cleanly unset ROS 1 settings and load ROS 2. Save and close the file (in nano, press Ctrl+O, Enter, then Ctrl+X).

#!/bin/bash
# Unset ROS 1 variables just in case
unset $(compgen -v | grep -E '^ROS|^CATKIN|^AMENT|^COLCON|^CMAKE|^PYTHONPATH')
unset LD_LIBRARY_PATH
unset PATH

# Rebuild minimal system PATH (for now)
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# Source ROS 2
source /opt/ros/foxy/setup.bash
echo "ROS 2 (Foxy) environment loaded."

Make the script executable (optional but useful):

chmod +x ~/.ros2_env.sh

🚀 Use the ROS 2 Environment

Whenever you want to work with ROS 2, open a new terminal and run:

source ~/.ros2_env.sh

🧪 Check Environment After Sourcing

After sourcing the ROS 2 setup script, you should see ROS 2–related environment variables like these:

printenv | grep -i ROS

Expected output:

ROS_VERSION=2
ROS_DISTRO=foxy
ROS_PYTHON_VERSION=3
AMENT_PREFIX_PATH=/opt/ros/foxy
PYTHONPATH=/opt/ros/foxy/lib/python3.8/site-packages
ROS_LOCALHOST_ONLY=0

You'll also notice changes in:

  • PATH
  • LD_LIBRARY_PATH

🛠️ Troubleshooting

If you keep seeing this error:

ModuleNotFoundError: No module named 'catkin_pkg'

…even though you've already installed the package, it could be due to a corrupted or misconfigured workspace build.

✅ Fix:

In your ROS 2 workspace directory, run the following:

cd ~/ros2_ws # go to the root of your ROS2 workspace
rm -rf build/ install/ log/
colcon build --symlink-install

It removes the build, install, log folders in your ROS 2 workspace and rebuild again.

Ready to start your ROS journey? This installation guide provides the foundation for working with both ROS 1 and ROS 2. Stay tuned for more detailed posts on ROS topics, including ROS 2 tutorials, navigation packages, and integration with modern robotics frameworks.