Ubuntu20.04下一键安装ROS1 Noetic

本文涉及的产品
资源编排,不限时长
简介: 本文提供了一个简化在Ubuntu 20.04系统上安装ROS1 Noetic过程的一键安装脚本工具,该脚本通过优化配置和使用清华大学镜像源,加速了国内用户的下载速度,并自动完成环境设置和依赖安装,同时提供了详细的使用说明和源码。

一键安装ROS1 Noetic

作者出于帮助国内朋友安装ROS需求,制作了这个脚本工具,能够帮助中国地区的朋友安装ROS1 Noetic Ubuntu20.04,并配置相关环境。

使用方式:

复制这行命令,在终端中执行:

wget -O $HOME/ros1_noetic_install.sh https://raw.githubusercontent.com/hermanye996/ros-install-one-click/main/ros1_noetic_install.sh && sudo chmod +x $HOME/ros1_noetic_install.sh && sudo bash $HOME/ros1_noetic_install.sh && rm $HOME/ros1_noetic_install.sh

如果无法连接到raw.githubusercontent.com,请先访问源码所在的托管网站,在根目录/home/<your_username>下手动下载ros1_noetic_install.sh文件,执行以下命令:

sudo bash ros1_noetic_install.sh

在这里插入图片描述

源码

该源码在Github开源,许可证为Apache License 2.0
最新源码链接:ros-install-one-click
V1.3源码如下,可供参考:

#!/bin/bash
#
# Description: 
# This is a shell script for installing ROS1 Noetic and its dependencies in Ubuntu 20.04 in China.
# It uses mirrors from Tsinghua University to speed up the download.
# The script also sets up the sudo privileges and modifies the sources.list file to update the repositories accordingly.
# It installs ROS1 Noetic and its dependencies, initializes rosdep, and verifies the installation by running roscore.
# It logs the installation progress and redirects the output to the console and logs files.
#
# Version: 1.3
# Date: 2023-06-12
# Author: Herman Ye @Realman Robotics
# License: Apache License 2.0
# Warning: This script is ONLY for ROS1 Noetic in ubuntu 20.04
# set -x
set -e



# UBUNTU CONFIGURATION BEGINS HERE

# Check if script is run as root (sudo)
if [ "$(id -u)" != "0" ]; then
    echo "This script must be run with sudo privileges. for example: sudo bash ros1_noetic_install.sh"
    read -p "Press any key to exit..."
    exit 1
fi
# Get script directory
SCRIPT_DIR=$(dirname "$0")
# Get the username of the non-root user
USERNAME=$SUDO_USER
echo "Current user is: $USERNAME"
# Save logs to files
LOG_FILE="${SCRIPT_DIR}/ros1_noetic_install.log"
ERR_FILE="${SCRIPT_DIR}/ros1_noetic_install.err"
rm -f ${LOG_FILE}
rm -f ${ERR_FILE}

# Redirect output to console and log files
exec 1> >(tee -a ${LOG_FILE} )
exec 2> >(tee -a ${ERR_FILE} >&2)

# Output log info to console
echo "ROS1 Noetic installation started!"  
echo "Installation logs will be saved to ${LOG_FILE}"
echo "Installation errors will be saved to ${ERR_FILE}"

# No Password sudo config
sudo sed -i 's/^%sudo.*/%sudo ALL=(ALL) NOPASSWD:ALL/g' /etc/sudoers

# Get architecture of the system
if [ $(uname -m) = "x86_64" ]; then
  MIRROR="https://mirrors.tuna.tsinghua.edu.cn/ubuntu/"
else
  MIRROR="https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/"
fi
echo "Current system architecture is: $(uname -m)"
echo "Current mirror is: $MIRROR"

# Backup original software sources
sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup

# Clear original software sources
sudo echo "" > /etc/apt/sources.list

# Replace software sources
echo "deb $MIRROR focal main restricted universe multiverse" >> /etc/apt/sources.list
echo "deb $MIRROR focal-updates main restricted universe multiverse" >> /etc/apt/sources.list
echo "deb $MIRROR focal-backports main restricted universe multiverse" >> /etc/apt/sources.list

if [ $(uname -m) = "x86_64" ]; then
  echo "deb http://security.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse" >> /etc/apt/sources.list
else
  echo "deb http://ports.ubuntu.com/ubuntu-ports/ focal-security main restricted universe multiverse" >> /etc/apt/sources.list
fi

# System update
sudo apt update
sudo apt upgrade -y

# Install pip
sudo apt install pip -y # If you haven't already installed pip

# Install gnome-terminal
sudo apt install gnome-terminal -y # If you haven't already installed gnome-terminal

# Set default pip source
pip config set global.index-url http://pypi.tuna.tsinghua.edu.cn/simple
pip config set global.trusted-host pypi.tuna.tsinghua.edu.cn

# ROS1 NOETIC INSTALLATION BEGINS HERE

# Configure your Ubuntu repositories
sudo add-apt-repository restricted
sudo add-apt-repository universe
sudo add-apt-repository multiverse

# Setup your sources.list
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'

# Add the ROS key
ros_key="${SCRIPT_DIR}/ros.key"
rm -f "${ros_key}"
wget http://packages.ros.org/ros.key
sudo apt-key add ros.key

# Update the system packages index to the latest version
sudo apt update

# Install Curl
sudo apt install curl -y # If you haven't already installed curl

# Install ROS1 Noetic
sudo apt install ros-noetic-desktop-full -y

# Install dependencies
sudo apt install python3-rosdep python3-rosinstall python3-rosinstall-generator python3-wstool build-essential -y

# Environment setup
if ! grep -q "source /opt/ros/noetic/setup.bash" /home/$USERNAME/.bashrc; then

    echo "# ROS1 Noetic Environment Setting" | sudo tee -a /home/$USERNAME/.bashrc
    echo "source /opt/ros/noetic/setup.bash" | sudo tee -a /home/$USERNAME/.bashrc
    echo "ROS1 Noetic environment setup added to /home/$USERNAME/.bashrc"
else
    echo "ROS1 Noetic environment is already set in /home/$USERNAME/.bashrc"
fi
source /home/$USERNAME/.bashrc

# Initialize rosdepc by fishros under BSD License
# https://pypi.org/project/rosdepc/#files
sudo pip install rosdep
sudo pip install rosdepc
# sudo pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -U rosdep
# Init & update rosdep 
sudo rosdepc init > /dev/null
#sudo rosdep fix-permissions
# su -l $USERNAME -c 'rosdepc update' > /dev/null
echo "rosdepc init completed!"

# System update again
sudo apt update
sudo apt dist-upgrade -y

# Verifying ROS1 installation
clear
# Define the variables to be printed
TEXT1="ROS1 Noetic installation completed!"
TEXT2="Please open a new terminal and run roscore to verify the installation:"
TEXT3="roscore"

# Define the colors
RED='\033[0;31m'
BLUE='\033[0;34m'
GREEN='\033[1;32m'
NC='\033[0m'

# Calculate the center of the terminal window
TERMINAL_WIDTH=$(tput cols)
TEXT1_PADDING=$((($TERMINAL_WIDTH-${#TEXT1})/2))
TEXT2_PADDING=$((($TERMINAL_WIDTH-${#TEXT2})/2))
TEXT3_PADDING=$((($TERMINAL_WIDTH-${#TEXT3})/2))

# Print the text in the center of the screen in the desired colors
echo ""
echo ""
echo ""
echo ""
echo ""
echo ""
echo ""
echo ""
echo ""
echo ""
echo -e "${GREEN}$(printf '%*s' $TEXT1_PADDING)${TEXT1} ${NC}"
echo -e "${NC}$(printf '%*s' $TEXT2_PADDING)${TEXT2} ${NC}"
echo -e "${RED}$(printf '%*s' $TEXT3_PADDING)${TEXT3} ${NC}"
echo ""
echo ""
echo ""
echo ""
echo ""
echo ""
echo ""
echo ""
echo ""
echo ""
相关实践学习
使用ROS创建VPC和VSwitch
本场景主要介绍如何利用阿里云资源编排服务,定义资源编排模板,实现自动化创建阿里云专有网络和交换机。
阿里云资源编排ROS使用教程
资源编排(Resource Orchestration)是一种简单易用的云计算资源管理和自动化运维服务。用户通过模板描述多个云计算资源的依赖关系、配置等,并自动完成所有资源的创建和配置,以达到自动化部署、运维等目的。编排模板同时也是一种标准化的资源和应用交付方式,并且可以随时编辑修改,使基础设施即代码(Infrastructure as Code)成为可能。 产品详情:https://www.aliyun.com/product/ros/
目录
相关文章
|
2月前
|
并行计算 Ubuntu Linux
Ubuntu学习笔记(五):18.04安装多版本CUDA
这篇博客文章介绍了在Ubuntu 18.04系统上如何安装和切换不同版本的CUDA,以及如何安装不同版本的cuDNN。
228 2
|
2月前
|
并行计算 PyTorch TensorFlow
Ubuntu安装笔记(一):安装显卡驱动、cuda/cudnn、Anaconda、Pytorch、Tensorflow、Opencv、Visdom、FFMPEG、卸载一些不必要的预装软件
这篇文章是关于如何在Ubuntu操作系统上安装显卡驱动、CUDA、CUDNN、Anaconda、PyTorch、TensorFlow、OpenCV、FFMPEG以及卸载不必要的预装软件的详细指南。
4118 3
|
19天前
|
Ubuntu 开发工具 git
Ubuntu安装homebrew的完整教程
本文介绍了如何在没有公网的情况下安装 Homebrew。首先访问 Homebrew 官网,然后通过阿里云的镜像克隆安装脚本,并创建普通用户进行安装。接着修改 `install.sh` 文件指向国内镜像,执行安装命令。最后配置环境变量并更换 Homebrew 源为国内镜像,确保安装顺利。
143 50
|
2月前
|
Ubuntu Linux 测试技术
Linux系统之Ubuntu安装cockpit管理工具
【10月更文挑战第13天】Linux系统之Ubuntu安装cockpit管理工具
151 4
Linux系统之Ubuntu安装cockpit管理工具
|
2月前
|
Ubuntu 应用服务中间件 nginx
Ubuntu安装笔记(三):ffmpeg(3.2.16)源码编译opencv(3.4.0)
本文是关于Ubuntu系统中使用ffmpeg 3.2.16源码编译OpenCV 3.4.0的安装笔记,包括安装ffmpeg、编译OpenCV、卸载OpenCV以及常见报错处理。
165 2
Ubuntu安装笔记(三):ffmpeg(3.2.16)源码编译opencv(3.4.0)
|
2月前
|
Ubuntu Linux C语言
Ubuntu安装笔记(二):ubuntu18.04编译安装opencv 3.4.0 opencv_contrib3.4.0
本文介绍了在Ubuntu 18.04系统上编译安装OpenCV 3.4.0及其扩展包opencv_contrib 3.4.0的详细步骤,包括下载源码、安装依赖、配置CMake和编译安装,以及常见问题的解决方法。
134 1
Ubuntu安装笔记(二):ubuntu18.04编译安装opencv 3.4.0 opencv_contrib3.4.0
|
2月前
|
Kubernetes Ubuntu Docker
从0开始搞K8S:使用Ubuntu进行安装(环境安装)
通过上述步骤,你已经在Ubuntu上成功搭建了一个基本的Kubernetes单节点集群。这只是开始,Kubernetes的世界广阔且深邃,接下来你可以尝试部署应用、了解Kubernetes的高级概念如Services、Deployments、Ingress等,以及探索如何利用Helm等工具进行应用管理,逐步提升你的Kubernetes技能树。记住,实践是最好的老师,不断实验与学习,你将逐渐掌握这一强大的容器编排技术。
179 1
|
2月前
|
Ubuntu Linux
软件安装(五):Ubuntu 18.04安装Teamviewer 看一遍就会
这篇文章介绍了在Ubuntu 18.04系统上通过图形界面和命令行两种方法安装TeamViewer远程控制软件的步骤。
39 2
|
28天前
|
消息中间件 Ubuntu Java
Ubuntu系统上安装Apache Kafka
Ubuntu系统上安装Apache Kafka
|
2月前
|
Ubuntu Linux
Ubuntu 16.04下无法安装.deb的解决方法
希望以上策略能有效协助您克服在Ubuntu 16.04中安装.deb文件时遇到的挑战。
39 0