Stolen from the ROS website.
sudo apt update && sudo apt install curl -y
export ROS_APT_SOURCE_VERSION=$(curl -s https://api.github.com/repos/ros-infrastructure/ros-apt-source/releases/latest | grep -F "tag_name" | awk -F\" '{print $4}')
curl -L -o /tmp/ros2-apt-source.deb "https://github.com/ros-infrastructure/ros-apt-source/releases/download/${ROS_APT_SOURCE_VERSION}/ros2-apt-source_${ROS_APT_SOURCE_VERSION}.$(. /etc/os-release && echo ${UBUNTU_CODENAME:-${VERSION_CODENAME}})_all.deb"
sudo dpkg -i /tmp/ros2-apt-source.debsudo apt install ros-rolling-desktop
Set up your environment by sourcing the following file:
source /opt/ros/rolling/setup.bash
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
If you installed ros-rolling-desktop above you can try some examples.
In one terminal, source the setup file and then run a C++ talker:
source /opt/ros/rolling/setup.bash
ros2 run demo_nodes_cpp talkerIn another terminal source the setup file and then run a Python listener:
source /opt/ros/rolling/setup.bash
ros2 run demo_nodes_py listenerYou should see the talker saying that it’s Publishing messages and the listener saying I heard those messages. This verifies both the C++ and Python APIs are working properly. Hooray!
sudo apt install ros-rolling-turtlesim
ros2 pkg executables turtlesim
ros2 run turtlesim turtlesim_node
Get this error?
ros2 run turtlesim turtlesim_node
/opt/ros/rolling/lib/turtlesim/turtlesim_node: symbol lookup error: /opt/ros/rolling/lib/turtlesim/turtlesim_node: undefined symbol: _ZN13rclcpp_action20ServerGoalHandleBase12try_abortingEv
[ros2run]: Process exited with failure 127A discussion about the cause is here: https://answers.ros.org/question/380917/