Ubuntu自动安装脚本

Ubuntu脚本,自动安装和升级Node.js、Python、Docker、npm、yarn和pip,并且使用国内源

#!/bin/bash

# 更新系统
sudo apt-get update
sudo apt-get upgrade -y

# 安装 curl
sudo apt-get install -y curl

# 设置国内源 (阿里,腾讯,清华大学)
set_ubuntu_mirrors() {
    sudo sed -i 's|http://us.|http://mirrors.aliyun.com/|g' /etc/apt/sources.list
    sudo apt-get update
}

# 安装或更新 Node.js 和 npm
install_node() {
    curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -
    sudo apt-get install -y nodejs
    npm config set registry https://registry.npm.taobao.org
    npm install -g npm
}

# 安装或更新 Python 和 pip
install_python() {
    sudo apt-get install -y python3 python3-pip
    pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
    sudo pip install --upgrade pip
}

# 安装或更新 Docker
install_docker() {
    curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
    sudo systemctl start docker
    sudo systemctl enable docker
}

# 安装或更新 Yarn
install_yarn() {
    curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
    echo "deb https://mirrors.aliyun.com/yarnpk/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
    sudo apt-get update
    sudo apt-get install -y yarn
    yarn config set registry https://registry.npm.taobao.org
}

# 调用函数
set_ubuntu_mirrors
install_node
install_python
install_docker
install_yarn

# 输出版本信息
echo "Node.js 版本:"
node -v
echo "npm 版本:"
npm -v
echo "Python 版本:"
python3 --version
echo "pip 版本:"
pip --version
echo "Docker 版本:"
docker --version
echo "Yarn 版本:"
yarn --version

标签

发表评论