刚开始接触Ubuntu的时候,不太清楚什么是源,但源又是Ubuntu下常用到的东西。因此,本文通过自己的理解简单介绍一下Ubuntu 源。
通过软件源安装软件的原理:
通过软件源安装软件的原理非常简单,Ubuntu 系统中自带了一个名为 apt的软件包管理工具,它的主要功能就是负责 管理Ubuntu 系统中所有软件包,其中包括从软件源中下载软件,卸载已经安装的软件等。而每当我们通过 sudo apt-get install 命令去安装一个软件时,apt 包管理工具就会从系统中一个叫做源列表的文件中去读取软件源的网址信息,查找可以包含该软件的软件源的网址,然后就从这个网址上把指定的软件给下载下来,然后由 apt 包管理工具在本地进行一些解压和安装的其他操作。
源,在Ubuntu下,它相当于软件库,需要什么软件,只用记得软件名就可以用命令安装:
比如我们在写程序的时候会用到vim、catkin。都可以通过
sudo apt-get install 软件名
来进行安装
如果源里没有这个软件时,此命令就没法完成,会有相应的报错提示。
如果需要卸载对应的软件,可以再终端中输入:
sudo apt-get remove软件名
在Ubuntu 的文件中/etc/apt/sources.list记录了Ubuntu官方源的地址,但是从国内访问国外的网站有“墙”,所以并不是所有的软件都能够下载,同时国外的服务器距离较远,访问速度比较慢。不过在国内有许多学校和公司的镜像网站都对 Ubuntu 的官方软件源进行了镜像备份,并且定期地进行同步更新,而在国内访问这些镜像网站的速度都要比直接访问 Ubuntu 官方镜像源要快地多,所以我们只要将 Ubuntu 官方软件源的网址替换成国内的 Ubuntu 软件源镜像网站的网址就可以达到加速的目的了。
更换源的方式
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak # 备份原来文件
sudo gedit /etc/apt/sources.list # 利用文本编辑器编辑里面是源 将其换成阿里源或者清华的源
确定自己的电脑系统
lsb_release -c
我的电脑是Codename: bionic
对应的阿里源:
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
对应清华源:
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
之前系统自带的部分直接删除即可,毕竟有备份文件。
采用
sudo apt-get update # 同步源
基本到这里就结束了,不过有时候,可能在使用sudo apt-get update
会出现
类似于这种的报错
问题:ubuntu18.04 使用apt-get update的时候报错E: 仓库 “http://ppa.launchpad.net/fcitx-team/nightly/ubuntu bionic Release” 没有 Release 文件。
解决:在etc/apt/sources.list.d 目录中删除对应的ppa比如这里是fcitx,那么为就将它加个bak后缀就好了问题解决。我当时在安装octave
软件的时候也出现过了。
Ubuntu 中常用安装软件的方式
在 Ubuntu 中软件安装的方式和 Windows 系统中双击 exe 文件的傻瓜式软件安装的方式有很大的不同,主要可以分为下面三种安装方式:
- 使用apt 包管理工具从软件源中安装
- 使用deb 格式的软件包安装
- 利用软件源码手动编译安装
apt相关
sudo apt update #同步源
sudo apt list --upgradeable #列出可升级的安装包
sudo apt upgrade #升级软件
sudo apt full-upgrade # 升级软件包并卸载当前软件包,作为系统升级使用
sudo apt install + 包名 # 安装时可能因依赖不满足而安装失败
sudo apt install -f +包名 # 修复安装依赖并安装软件
sudo apt remove + 包名 # 删除包,保留配置文件
sudo apt purge + 包名 # 删除包及配置文件
sudo apt autoremove # 自动清理不再使用的依赖与库文件 ,轻易不要使用会多删除很多内容
sudo apt list --installed # 列出已安装的软件包
dpkg相关
用于安装.deb的包
dpkg -i package.deb # 安装包
dpkg -V package # 验证包的完整性
dpkg -l package # 显示该包版本
dpkg -L package # 显示该包关联文件
dpkg -r package # 删除包
dpkg -P package # 删除包及配置文件
dpkg --unpack # 解包
dpkg --configure # 配置包
dpkg -c package.deb # 列出deb包内容
dpkg -S package # 搜索所属包内容
安装源码
安装.tar.gz压缩格式的软件源码包
sudo tar -zxvf filename.tar.gz 得到 (filename) 文件夹
然后cd filename
输入sudo ./configure 配置环境,生成makefile
输入sudo make 编译源代码生成二进制代码(目标文件)
输入sudo make install 执行安装
安装完成之后输入sudo make clean 清除目标文件