Hi There! This is perhaps a few years late, but I wanted to share this with anyone who may find it useful. I documented a little command-line tool I created a while ago for quickly switching between ROS1 and ROS2 in the terminal:
As someone who occasionally has to run/maintain both ROS1 and ROS2 packages, it’s been a huge help.
Here’s how it works:
Open a new terminal, notice that it shows:
ROS 1 Environment Sourced
If you want to switch to ROS2 simply type:
rs 2
And now it says
ROS 2 Environment Sourced
That’s it! no concerns about mixed up environment variables.
2 Likes
Hey 
Sorry for the necromancy, but I just came across this while cleaning my tabs.
Back in the days when Anaconda and ROS 1 were clashing I wrote something similar but a bit more general:
It is a small CLI tool to handle multiple environments (could be ROS 1 and ROS 2 but could also be multiple workspaces or anything else really).
Essentially, you can create small files of bash code that are sourced based on the currently set environment.
So, you would create an environment ros1 and add to that file the code to source your ros1 workspace and anything relevant to that.
You can also edit them later on.
When loading the terminal it will look up which environment is active and source the relevant file.
You can switch the environment for all future terminals or just the current terminal.
All commands have tab completion.
2 Likes