Running ROS 1 Noetic and ROS 2 Foxy From Source on Ubuntu 20.04
Introduction
Running both ROS 1 (Noetic) and ROS 2 (Foxy) on the same system can be challenging due to differences in dependencies, environment variables, and communication mechanisms. However, Ubuntu 20.04 remains the best option for managing both distributions, as Noetic is the last ROS 1 release and Foxy is a long-term support (LTS) release of ROS 2.
This guide will walk you through the process of installing, sourcing, and managing both ROS versions from source while minimizing conflicts.
Key Topics Covered
- Installing ROS 1 Noetic from source
- Installing ROS 2 Foxy from source
- Managing environment variables to switch between Noetic and Foxy
- Running a ROS 1-ROS 2 bridge for interoperability
1. Installing ROS 1 Noetic From Source
Since Ubuntu 20.04 is the preferred OS for ROS Noetic, you can follow these steps to build it from source.
Step 1: Install Dependencies
sudo apt update && sudo apt upgrade -y
sudo apt install -y python3-rosdep python3-rosinstall-generator \
python3-vcstool build-essential
Initialize rosdep
:
sudo rosdep init
rosdep update
Step 2: Create a Workspace and Clone ROS 1
mkdir -p ~/ros1_noetic/src
cd ~/ros1_noetic
rosinstall_generator desktop --rosdistro noetic --deps --tar > noetic.rosinstall
vcs import --input noetic.rosinstall src
rosdep install --from-paths src --ignore-src -r -y
Step 3: Build ROS 1
cd ~/ros1_noetic
colcon build --symlink-install
Step 4: Source ROS 1
echo 'source ~/ros1_noetic/install/setup.bash' >> ~/.bashrc
source ~/.bashrc
Verify installation:
echo $ROS_DISTRO # Should output 'noetic'
2. Installing ROS 2 Foxy From Source
Since Noetic and Foxy have different architectures, we will install ROS 2 Foxy in a separate workspace.
Step 1: Install Dependencies
sudo apt install -y python3-colcon-common-extensions \
python3-vcstool git wget
Step 2: Create a Workspace and Clone ROS 2
mkdir -p ~/ros2_foxy/src
cd ~/ros2_foxy
vcs import src < https://raw.githubusercontent.com/ros2/ros2/foxy/ros2.repos
rosdep install --from-paths src --ignore-src -r -y
Step 3: Build ROS 2
cd ~/ros2_foxy
colcon build --symlink-install
Step 4: Source ROS 2
echo 'source ~/ros2_foxy/install/setup.bash' >> ~/.bashrc
source ~/.bashrc
Verify installation:
echo $ROS_DISTRO # Should output 'foxy'
3. Managing ROS 1 and ROS 2 Environments
By default, sourcing both ROS 1 and ROS 2 together will cause conflicts. To manage this, create separate aliases:
Option 1: Use Aliases to Switch Between ROS Versions
Add these lines to your ~/.bashrc
:
alias source_ros1="source ~/ros1_noetic/install/setup.bash"
alias source_ros2="source ~/ros2_foxy/install/setup.bash"
Now, you can quickly switch between them:
source_ros1 # Switch to ROS Noetic
source_ros2 # Switch to ROS 2 Foxy
Option 2: Use Separate Terminals
For seamless operation, open two terminals:
-
Terminal 1 (ROS 1 Noetic)
source ~/ros1_noetic/install/setup.bash roscore
-
Terminal 2 (ROS 2 Foxy)
source ~/ros2_foxy/install/setup.bash ros2 run demo_nodes_cpp talker
4. Running the ROS 1-ROS 2 Bridge
To communicate between ROS 1 and ROS 2, use ros1_bridge
.
Step 1: Install ros1_bridge
source_ros1
source_ros2
sudo apt install -y ros-foxy-ros1-bridge
Step 2: Run the Bridge
ros2 run ros1_bridge dynamic_bridge
Now, any topic published in ROS 1 will be available in ROS 2, and vice versa.
5. Debugging Common Issues
Problem: ROS 1 and ROS 2 Variables Overlapping
Solution: Always source only one ROS version at a time or use separate terminals.
Problem: colcon Build Fails
Solution: Ensure all dependencies are installed using rosdep update && rosdep install --from-paths src --ignore-src -r -y
.
Problem: ROS 1-ROS 2 Bridge Fails to Start
Solution:
- Ensure both source_ros1
and source_ros2
are sourced.
- Try restarting the bridge with ros2 run ros1_bridge dynamic_bridge
.
Conclusion
By following this guide, you can successfully install, source, and run both ROS 1 Noetic and ROS 2 Foxy on Ubuntu 20.04 without conflicts. Using environment management strategies such as aliases and separate terminals ensures smooth switching between versions.
The addition of ros1_bridge
further enables seamless communication, making hybrid ROS 1/2 projects possible.
Happy Coding! 🚀