在Ubuntu上更改apt源并安装python和c++
- 更改apt源
首先,备份现有的apt源代表:
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
编辑APT源列表:
sudo nano /etc/apt/sources.list
将源列表内容更改为以下内容(以阿里云源为例):
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
保存并退出编辑器(按 Ctrl+O 保存,然后按 Ctrl+X 退出)。
更新APT包索引:
sudo apt update
更新应用:
sudo apt upgrade
- 安装python
首先,检查默认python版本
python3 --version
如果需要特定版本的Python,可以使用以下命令安装:
sudo apt install python3.x
安装pip包管理工具:
sudo apt install python3-pip
pip3 --version
- 安装c++
sudo apt install g++
g++ --version
sudo apt install build-essential # c++开发常用工具
可能安装g++时报错,可以按照提示执行
sudo apt autoremove