If you don’t want to have to source the setup file every time you open a new shell (skipping task 1), then you can add the command to your shell startup script:
echo "source /opt/ros/foxy/setup.bash" >> ~/.bashrc
To undo this, locate your system’s shell startup script and remove the appended source command.
To undo this (to change to another distro) in Linux and macOS, locate your system’s shell startup script and remove the appended source command.
Sourcing ROS 2 setup files will set several environment variables necessary for operating ROS 2. If you ever have problems finding or using your ROS 2 packages, make sure that your environment is properly set up using the following command:
printenv | grep -i ROS
Check that variables like ROS_DISTRO and ROS_VERSION are set. For example, if you’re using Foxy, you would see:
ROS_VERSION=2
ROS_PYTHON_VERSION=3
ROS_DISTRO=foxy
If the environment variables are not set correctly, return to the ROS 2 package installation section of the installation guide you followed. If you need more specific help (because environment setup files can come from different places).