Official linkYou need to have an active internet connection and must be running Ubuntu 18.04 (check Additional > Alternatives for other versions).
To install ROS perform the following steps
- Open the application Software and Updates and see that the options showing main, universe, restricted and multiverse are checked.
- Open a terminal window (Ctrl + Alt + T)
- Update everything on your system. Type in the following commands and press Enter after every command to execute it
sudo apt update
sudo apt upgrade -y
- Setup the sources so that your system can receive updates from packages.ros.org. Type in the following commands into the terminal and press Enter after every command to execute it
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
- You can check the Other Software section in Software and Updates application. A new line for packages.ros.org might have been added.
- You can also verify the action by running the following command (and the output will have a link):
cat /etc/apt/sources.list.d/ros-latest.list
- You could also do it using the GUI. Click the 'Add...' button enter "http://packages.ros.org/ros/ubuntu bionic main" and 'Add source'.
- Setup your keys for the keyserver. These will let you access the server and will let the server send things to you. Until now, you've only added it to the list, now you authenticate it. Type in the following commands into the terminal and press Enter after every command to execute it
sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116
- You must get an output telling that the public key for ROS builder has been imported
- Get the package index up to date so that it recognises the updates and packages available. Type in the following commands into the terminal and press Enter after every command to execute it
sudo apt update
- You must have noticed that there are entries from "http://packages.ros.org/ros" this time. This means everything till now has gone fine and that you're ready for the main installation.
- Perform a desktop full install for ROS. Type in the following commands into the terminal and press Enter after every command to execute it
sudo apt install -y ros-melodic-desktop-full
- This will fetch about 530MB of content, so it might take some time
- Now we need to setup rosdep. This is a tool that helps us install system dependencies for ROS. It is also essential for propoer functioning of some core components in ROS. Type in the following commands into the terminal and press Enter after every command to execute it
sudo rosdep init
- This initialises the rosdep tool. It basically creates a list of essential things at a location. It can be seen in the output of the command
rosdep update
- It updates the cache and reads sources
- Setup the ROS environment by running the setup script. Type in the following commands into the terminal and press Enter after every command to execute it
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
- This basically appends the line "source /opt/ros/melodic/setup.bash" in the ~/.bashrc file. You can alternatively open the file through a command like sudo nano ~/.bashrc, write "source /opt/ros/melodic/setup.bash" in the end and close it (Ctrl + X) and save it (Press 'Y' and then 'Enter').
- By putting this line in the "~/.bashrc" file, ROS would be set up everytime you launch a new terminal
source ~/.bashrc
- This basically refreshes the current terminal with the updated ".bashrc" file. You could alternatively close and reopen the terminal and it would have the same effect.
- Add dependencies for building packages. These are tools that help us handle workspaces in ROS. Type in the following commands into the terminal and press Enter after every command to execute it
sudo apt install -y python-rosinstall python-rosinstall-generator python-wstool build-essential
- This installs the essential tools for python dependencies of ROS.
That's it ! You've successfully installed ROS on your system
Checking your ROS installation
To check if ROS has properly been installed or not, Type in the following commands into the terminal and press Enter after every command to execute it
printenv | grep ROS
- This will show you environment variables with "ROS" in their name. Check the ROS_PACKAGE_PATH (it must be "/opt/ros/melodic/share") and ROS_DISTRO (it must be "melodic").