Ubuntu 当中的常见问题

一、apt 下载太慢

1、背景

Ubuntu使用的下载源服务器在国外,因此在使用的的时候,特别的慢,因此换国内的Ubuntu镜像源,便成了解决速度慢的优选方案。国内的知名镜像源有很多,比如阿里云、华为云、清华大学镜像源……等国内知名镜像源。

2、修改配置文件

1、备份配置文件

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

2、使用编辑器打开配置文件

sudo gedit /etc/apt/sources.list
这里用的gedit编辑器,比vim和vi更方便操作

3、在**阿里开源镜像站**当中,找到对应的配置,复制粘贴全部替换。

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

在这里插入图片描述

2、更新源(两个命令全部需要执行)

sudo apt-get update
这个命令,会访问源列表里的每个网址,并读取软件列表,然后保存在本地电脑。
我们在新立得软件包管理器里看到的软件列表,都是通过update命令更新的。
sudo apt-get upgrade
这个命令,会把本地已安装的软件,与刚下载的软件列表里对应软件进行对比,如果发现已安装的软件版本太低,
就会提示你更新。如果你的软件都是最新版本,会提示:
    升级了 0 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 0 个软件包未被升级。

update和upgrade的区别不是很大,侧重点不同而已。

update侧重更新的意思,主要是为原有的东西增加新功能,或者对已有的部分做出更改等。比如,数据库更新数据,那么就是update,而不能用upgrade。

upgrade侧重升级的意思,是指从较低级版本升级到高级的版本,这种升级往往伴有新功能的增加,因此也有update的意思。比如,升级套餐,只能用upgrade,而不能用update。

但是在计算机领域,软件、系统的更新和升级往往是同一个意思,在这种环境中update和upgrade是可以通用的。只是往细了说update是量上的变化,而upgrade质上的变化。

二、在 Ubuntu 当中安装 python3.9

1、打开系统上的终端,然后为系统配置Deadsnakes PPA。

sudo add-apt-repository ppa:deadsnakes/ppa

日常开发/部署操作中我们经常会遇到安装Python的需求,然而有的时候Ubuntu自带的软件源中的Python版本并不能满足我们在程序中使用一些较新特性的需求。
这时除了自行编译Python之外,我们还有另外一种选择,那就是使用一个由第三方维护的PPA软件源来方便的安装所需要的Python版本

2、直接下载

sudo apt update
sudo apt install python3.9

3、查看版本

python3.9 -V

三、将Ubuntu 当中默认 python 指令更改为自己安装的 python 3.9

在ubuntu18.04上有自带有python2.7和3.6,你也可以使用更新版本的python。

我这里下载的python3.9,这里将python3.9设为默认的。

sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 2

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.9 3

这里使用的是优先级设置,后面的数字越大,优先级越高。
此时输入命令python, 可以看到系统默认的是python3.9啦!
在这里插入图片描述

四、在Ubuntu当中安装 pip,更新 pip

1、安装

apt install python3-pip

那么,什么是 pip 呢?pip 是 Python 的包管理器。这意味着它是一个工具,允许你安装和管理不属于标准库的其他库和依赖。
更多可以看:什么是pip?

2、更新

pip3 install --upgrade pip

猜你喜欢

转载自blog.csdn.net/vincent3678/article/details/112723813