Ubuntu安装源

最近在Ubuntu上面安装软件,折腾了一段时间,把一些关于安装源的内容总结一下。

1 前言

安装源和系统的版本(16.04,18.04等)、架构(x86,arm64等)都相关,所以在使用源之前,需要先确定所安装机器的系统和架构。

1.1 查看系统发行版本

cat /etc/issue

Ubuntu 16.04.2 LTS \n \l

CentOS release 6.3 (Final)
Kernel \r on an \m

或者

lsb_release -a

No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 16.04.2 LTS
Release:	16.04
Codename:	xenial

LSB Version:	:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID:	CentOS
Description:	CentOS release 6.3 (Final)
Release:	6.3
Codename:	Final

1.2 查看系统内核版本

cat /proc/version

Linux version 4.4.77 (zouxf@mid-server) (gcc version 4.9.x-google 20140827 (prerelease) (GCC) ) #329 SMP Mon Dec 18 15:44:03 CST 2017

Linux version 3.10.0.514.26.2.el7.x86_64 ([email protected]) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC) ) #4 SMP Wed Aug 16 17:09:53 CST 2017

1.3 查看架构

uname -a

Linux hostname 3.10.0.514.26.2.el7.x86_64 #4 SMP Wed Aug 16 17:09:53 CST 2017 x86_64 x86_64 x86_64 GNU/Linux

Linux username 4.4.77 #329 SMP Mon Dec 18 15:44:03 CST 2017 aarch64 aarch64 aarch64 GNU/Linux

Darwin appledeMacBook-Pro.local 19.4.0 Darwin Kernel Version 19.4.0: Wed Mar  4 22:28:40 PST 2020; root:xnu-6153.101.6~15/RELEASE_X86_64 x86_64

或者 

arch

返回
x86_64 、aarch64 、i386

2 源列表文件

在Ubuntu系统中,控制软件安装更新的源服务器地址的文件是 /etc/apt/sources.list (在CentOS中是 /etc/yum.conf, /etc/yum.repos.d/, /etc/yum/)。和sources.list功能一样的是/etc/apt/sources.list.d/*.list(*代表一个文件名,只能由字母、数字、下划线、英文句号组成)。sources.list.d目录下的*.list文件为在单独文件中写入源的地址提供了一种方式,通常用来安装第三方的软件。

2.1 示例

deb http://archive.ubuntu.com/ubuntu/ trusty main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse

以上是Ubuntu官方的14.04版本的源列表文件内容。

2.2 具体含义

deb      http://archive.ubuntu.com/ubuntu/ trusty   main    restricted universe multiverse
档案类型  镜像URL                            发行版本  软件仓库1 软件仓库2   软件仓库3  软件仓库4

2.2.1 档案类型 (Archive type)

  • deb关键字表示二进制预编译软件包来源,我们一般用的就是这种档案类型。
  • deb-src关键字表示软件包的源代码包来源。

2.2.2 镜像url

表示源文件的地址,其中以 ubuntu 结尾表示支持 x86 的架构版本,以 ubuntu-port 结尾表示支持 arm64 的架构版本。

发行版本distributions内容所在目录

pool/main/目录下按源码包名称的首字母归档

每一个源目录下都应该至少包含distspool两个目录,否则就是无效的源。以下是各目录详情:

  • /dists/ 目录内存放着各 发行版(distributions)文件,如 trusty,xenial等。
  • /pool/ 目录为软件包的物理地址。软件包均放进一个巨大的 池子(pool),按照源码包名称分类存放。为了方便管理,pool 目录下按属性再分类(main,restricted, universe, multiverse),分类下面再按源码包名称的首字母归档。这些目录包含的文件有:运行于各种系统架构的二进制软件包生成这些二进制软件包的源码包。你可以执行命令 apt-cache showsrc packageNameToBeInstalled 查找看源码包的文件信息,其中 Directory 会显示该软件包的存放位置。例如: apache2 软件包存放在 pool/main/a/apache2/ 目录中。另外,由于lib*软件包数量巨大它们以特殊的方式归档,例如libpaper 软件包存放在 pool/main/libp/libpaper/。
  • /indices/ 目录为维护人员文件和重载文件。
  • /project/ 目录大部分为开发人员的资源,如 project/experimental/,本目录包含了处于开发中的软件包和工具,它们均处于 alpha 测试阶段。用户不应使用这些软件因为即使是经验丰富的用户也会被搞得一团糟。

2.2.3 开发版本

发行版有两种分类方法:

  • 发行版的具体代号,如18.04是bionic,16.04是xenial,trusty,precise 等。
  • 发行版的发行类型,如oldstable,stable,testing 和 unstable。

后面的进一步指定词具体含义如下:

  • -security:仅修复漏洞,并且尽可能少的改变软件包的行为。低风险。

  • -backports:backports的团队则认为最好的更新策略是security策略加上新版本的软件(包括候选版本的)。但不会由Ubuntu security team审查和更新。

  • -updates:修复严重但不影响系统安全运行的漏洞,这类补丁在经过QA人员记录和验证后才提供,和security那类一样低风险。

  • -proposed:update类的测试部分,仅建议提供测试和反馈的人进行安装。

2.2.4 软件仓库

各仓库的名称代表其软件自由度,含义如下(原文

  • main: Officially Supported, Open-Source Software,官方支持的,且开源的软件
  • restricted: Officially Supported, Closed-Source Software,官方支持的,闭源的软件
  • universe: Community-Maintained, Open-Source Software,社区/论坛维护的,开源的软件
  • multiverse: Unsupported, Closed-Source and Patent-Encumbered Software,不受支持的,闭源的,有专利限制或阻碍的软件

从上述的具体含义可以看出,我们用的示例,表示的是 Ubuntu 14.04 版本 x86架构 的软件源列表。

 

3 国内源

由于官方源在国外,安装软件时速度比较慢,所以在这里整理了一些国内的镜像源地址。

注意,这里有一些是arm64的源地址。

 

4 更新软件源

cd /etc/apt
cp sources.list  sources.list.bak 备份原来的自带的源
sudo vi  /etc/apt/sources.list    将新源列表信息写入该文件

之后执行

sudo apt-get update

这个命令,会访问源列表里的每个网址,并读取软件列表,然后保存在本地电脑。我们在软件包管理器里看到的软件列表,都是通过update命令更新的。

在这之后还可以执行

sudo apt-get upgrade

这个命令,会把本地已安装的软件,与刚下载的软件列表里对应软件进行对比,如果发现已安装的软件版本太低,就会提示你更新。如果你的软件都是最新版本,会提示:升级了 0 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 0 个软件包未被升级。

总之,update是更新软件列表,upgrade是更新各软件本身。

 

5 常用命令

5.1 apt-get命令

apt-get 命令一般用于软件包的安装,更新和移除,下面是它的一些常用命令

命令 功能介绍
update 将软件仓库中的软件包列表更新到本地,一般我们在安装软件之前需要执行该操作
upgrade 升级系统中的所有软件包,如果一个软件包在升级时会导致其他已安装的软件包被删除,那么这个软件包将不会被升级
dist-upgrade 该命令时upgrade的升级版,它会尝试去解决安装时出现冲突,比如会删除已安装的软件包,所以慎用
remove 卸载软件包(保留配置文件),同时也会卸载依赖于该软件的包,A依赖于B,卸载B时也会卸载A
install 安装软件包
source 下载源码包
clean 删除本地缓存的所有软件安装包
check 检查是否存在有问题的依赖关系

当然,在使用apt-get时还可以带一些选项,关于apt-get的详细说明可以查看手册man apt-get

5.2 apt-cache命令

apt-cache一般用于软件包查找和显示软件包信息。当我们安装某个软件包时,但是却不知道具体包名时可以使用apt-cache进行查找

查找mysql数据库安装包的包名
apt-cache search mysql

显示mysql-server(也就是mysql数据库)的安装包信息
apt-cache show mysql-server

 

6 aarch64 和 arm64

在上面提到,源列表和CPU架构有关,分 x86 和 arm64。而我们通过arch命令获取到的系统架构,返回的是 aarch64。那么这个 aarch64 和 arm64 是什么关系呢?

这里找到一段文字

AArch64 is the 64-bit state introduced in the Armv8-A architecture (https://en.wikipedia.org/wiki/ARM_architecture#ARMv8-A). The 32-bit state which is backwards compatible with Armv7-A and previous 32-bit Arm architectures is referred to as AArch32. Therefore the GNU triplet for the 64-bit ISA is aarch64. The Linux kernel community chose to call their port of the kernel to this architecture arm64 rather than aarch64, so that's where some of the arm64 usage comes from.

As far as I know the Apple backend for aarch64 was called arm64 whereas the LLVM community-developed backend was called aarch64 (as it is the canonical name for the 64-bit ISA) and later the two were merged and the backend now is called aarch64.

So AArch64 and ARM64 refer to the same thing.

AArch64 是 在Armv8-A 架构中 被引入的 64位状态。32位状态 对应着 AArch32,它吉向后兼容 Armv7-A 和 以前的 32位 Arm架构。因此,64位的工业标准体系结构 的 GNU 三元组接口 是 aarch64。Linux内核社区选择 将 内核到这个架构 的端口 叫成 arm64 而不是 aarch64,这就是 arm64 用法的来源。

据我说知,Apple的 aarch64 后端 曾被叫做 arm64,而 LLVM 社区开发版的 后端 被叫做 aarch64 (因为这是64位工业标准体系结构中收录的经典叫法),在这之后,这两者合并,于是后端现在被叫做 aarch64。

所以,AArch64 和 ARM64 指向同一个东西。

官方的arm64源地址是 http://ports.ubuntu.com/ubuntu-ports/dists 。我们可以通过在源文件中,查找 binary_arm64 字样的文件,来确认该源是否支持arm64架构的系统。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章