> 文章列表 > 【Linux】【环境】系统分类及环境配置

【Linux】【环境】系统分类及环境配置

【Linux】【环境】系统分类及环境配置

一、系统分类

Linux发行版可以按照不同的分类方式进行归类,其中最常见的是按照家族分类。以下是一些Linux发行版的家族分类及其包管理器:

Debian家族:apt-get/aptitude/dpkg

  • Debian:最早的Linux发行版之一,以稳定性、安全性和易用性著称。
  • Ubuntu:基于Debian的操作系统,着重于用户友好性和易用性。
  • Linux Mint:基于Ubuntu的操作系统,拥有良好的用户界面和易用性。

Red Hat家族:RPM package manager/YUM/DNF

  • Red Hat Enterprise Linux(RHEL):商业化的Linux发行版,主要用于企业级应用
  • Fedora:社区开发的操作系统,定位于开发者和技术爱好者,更新频繁且具备先进的功能。
  • CentOS:基于RHEL的免费发行版,被广泛应用于服务器领域。

二、系统源

Linux 系统源可以分为官方源和第三方源两种。

官方源是由 Linux 发行版的官方团队维护的软件仓库,提供与该发行版兼容的软件包。用户可以直接从这些源中获取安全可靠的软件更新。例如,Ubuntu 的官方源包括主服务器、美国服务器、欧洲服务器等多个镜像源,每个镜像源都提供了 Ubuntu 官方软件包。

第三方源指的是由社区或个人维护的软件仓库,提供不在官方源中的软件包或者新版本的软件包。这些源有时可能会存在安全问题或不兼容问题,因此需要谨慎使用。常见的第三方源包括 RPM Fusion、EPEL 和 Arch User Repository (AUR) 等。

以 Ubuntu 为例,官方源的配置文件位于 /etc/apt/sources.list 或 /etc/apt/sources.list.d/ 下,可以通过编辑这些配置文件来添加、删除或修改源。例如,如果要添加一个名为“example”的第三方源,可以在 sources.list.d 目录下创建一个名为 example.list 的文件,并将以下内容添加到文件中:

deb http://example.com/ubuntu bionic main
deb-src http://example.com/ubuntu bionic main

其中,deb 表示二进制软件包的地址,deb-src 表示源代码的地址;http://example.com/ubuntu 是源的网址;bionic 是 Ubuntu 版本号;main 是存储库的名称。添加完源后,需要运行 sudo apt update 命令更新软件包列表。

总之,在使用 Linux 系统时,了解并正确配置系统源是非常重要的,可以帮助用户获取适合自己的软件包,并保证系统的安全可靠性。

在 Debian 中,修改 /etc/apt/sources.list 文件后需要运行 apt-get update
命令才能使更改生效。这个命令会更新包含在 sources.list 文件中的软件包列表,以便系统可以找到新添加的源并从其中获取软件包。

要执行此操作,请打开终端并以 root 用户身份运行以下命令:

bash sudo apt-get update

该命令将连接到所添加的所有源,并更新本地存储库以确保您可以访问其软件包。完成后,您就可以使用新源中可用的软件包了。

示例:

ubuntu 20.04

#阿里源
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse

ubuntu 18.04

#阿里源
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb 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 main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

三、更改python源

~/.pip/pip.conf 文件是 pip 命令的配置文件,用于指定 pip 命令在安装 Python 包时使用的源、代理、缓存等选项

此配置文件包含多个配置项,例如:

[global]: 全局选项,适用于所有命令
[install]: 安装命令选项
[uninstall]: 卸载命令选项
[wheel]: 生成和安装 wheel 包的选项
[cache]: 缓存选项
[proxy]: 代理选项

例如,您可以在 ~/.pip/pip.conf 中设置国内的 PyPI 镜像源,以加速包的下载和安装:

[global]
index-url = https://mirrors.aliyun.com/pypi/simple/

这样,当您使用 pip install 命令安装 Python 包时,pip 将会从上述指定的镜像源下载包,而不是默认的官方源。

示例:

[global]timeout=100index-url=https://pypi.tuna.tsinghua.edu.cn/simple/extra-index-url=http://mirrors.aliyun.com/pypi/simple/[install]trusted-host=pypi.tuna.tsinghua.edu.cnmirrors.aliyun.com