Ubuntu 常用环境配置记录
引言
经常使用 Ubuntu 虚拟机,双系统,WSL,服务器等等,每次配置常用开发环境都要去百度细节,故在此记录一下;
更换软件源
# 更新
sudo apt update && sudo apt upgrade
安装 Docker
# 更新ubuntu的apt源索引
sudo apt update
# 安装包允许apt通过HTTPS使用仓库
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
# 添加Docker官方GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
# 设置Docker稳定版仓库
add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
# 安装docker
sudo apt update && sudo apt install docker-ce
# 更换docker镜像源,向 /etc/docker/daemon.json 中添加:
{
"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"]
}
# 重启docker服务
service docker restart
# 检查配置是否生效
sudo docker info | grep Mirrors -A 1
安装 VSCode
# 添加源
wget -q https://packages.microsoft.com/keys/microsoft.asc -O- | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main"
# 更新并安装
sudo apt update && sudo apt install code
配置 NodeJs
# 新建软件包文件夹,用来存放此类软件;
mkdir ~/app
# 从官网下载Linux二进制文件
wget https://npm.taobao.org/mirrors/node/latest-v12.x/node-v12.18.1-linux-x64.tar.xz
# 解压
tar xvJf node-v12.18.1-linux-x64.tar.xz -C ~/app
# 向 ~/.bashrc 中添加:
for dir in $(ls $HOME/app/)
do
[ -d $HOME/app/$dir/bin ] && export PATH=$HOME/app/$dir/bin:$PATH
done
# 重启命令行后更换 npm 源
npm config set registry http://registry.npm.taobao.org/
配置 Rust
- 官网教程;
# 配置 rustup 镜像,向 ~/.bashrc 添加:
export RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup
export RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static
export PATH=$HOME/.cargo/bin:$PATH
# 安装 rustup
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# 换源,向 ~/.cargo/config 中添加:
[source.crates-io]
replace-with = 'tuna'
[source.tuna]
registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"
配置 MongoDB
# 导入包管理系统使用的公钥
wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -
# 为MongoDB创建一个列表文件(对于18.04,其他版本替换 bonic)
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list
# 更新并安装
sudo apt update && sudo apt install -y mongodb-org
# 锁定安装版本
echo "mongodb-org hold" | sudo dpkg --set-selections
echo "mongodb-org-server hold" | sudo dpkg --set-selections
echo "mongodb-org-shell hold" | sudo dpkg --set-selections
echo "mongodb-org-mongos hold" | sudo dpkg --set-selections
echo "mongodb-org-tools hold" | sudo dpkg --set-selections
# 启动 mongodb
sudo mkdir -p /data/db
sudo mongod --fork --logpath=/data/mongod.log
配置 Jupyter
# 安装 pip3
sudo apt install -y python3-pip
# 切换 pip 镜像源,向 ~/.pip/pip.conf 中添加:
[global]
index-url = https://mirrors.aliyun.com/pypi/simple
# 安装 jupyter
sudo pip3 install jupyter
# 设置密码
jupyter notebook password
# 切换 jupyter 工作区并后台运行
mkdir ~/jupyter && cd ~/jupyter
nohup jupyter notebook --no-browser --ip 0.0.0.0 --port 2000 --allow-root --NotebookApp.allow_origin='*' > ~/.jupyter/log &
方便添加 .gitignore
- 官网教程;
# 向 .bashrc 里添加:
function gi() { curl -sL https://www.toptal.com/developers/gitignore/api/$@ ;}
# 生成 .gitignore 命令:
gi rust >> .gitignore
总结
不断更新~
转载请标明出处及链接
事皆有定数,唯尽力而为,便不再遗憾

浙公网安备 33010602011771号