原文链接:ubuntu镜像换源 环境变量配置
linux服务器环境配置
系统配置
host
配置ip与主机名的配置,分布式系统需要配置
1 | sudo vim /etc/hosts |
hostname
修改主机名称,需要与hosts中的配置保持一致
1 | sudo vim /etc/hostname |
系统变量
- 使用export设置
设置删除1
export VARIABLE_NAME=variable_value
1
unset VARIABLE_NAME
- 直接编辑环境变量
编辑系统环境变量1
2sudo vim /etc/profile
export x=/usr/bin/x # 变量路径
保存后使用 source /etc/profile 生效
用户变量
用户变量一般在用户路径下~/.bashrc,与系统环境变量配置相同
1 | sudo vim ~/.bashrc |
系统换源
apt镜像
apt源在路径/etc/apt/sources.list
先将当前源备份
1 | sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup |
然后将需要的源输入保存后执行
1 | sudo apt-get update #更新源 |
清华源 https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse
# deb-src http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse中科大源
http://mirrors.ustc.edu.cn/
http://mirrors.ustc.edu.cn/help/ubuntu.html
1 | # 默认注释了源码仓库,如有需要可自行取消注释 |
阿里源 https://developer.aliyun.com/mirror/ubuntu
1 | deb https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse |
pip换源
如果不希望换源,可以直接在安装命令后加 -i https://pypi.tuna.tsinghua.edu.cn/simple指定源安装
1 | mkdir ~/.pip |
1 | 清华 https://mirror.nju.edu.cn/pypi/web/simple/ |
注意
镜像源并不一定与初始源相同,而且对于不同发行版本也应该使用对应源,不同源会导致软件不适配问题。
如果出现问题可以切换源或者换回官方源
官方apt源
1 | #deb cdrom:[Ubuntu 20.04 LTS _Focal Fossa_ - Release amd64 (20200423)]/ focal main restricted |
官方pip源,有些源在未发布时只存在test源中
1 | https://pypi /simple |