当前位置: 首页 > news >正文

ARM Linux 基础学习 / Ubuntu 下的包管理 / apt工具

编辑整理 by Staok。

注:在 Github 上的原版文章日后可能会更新,在其它位置发的不会跟进。文章的 Gitee 仓库地址,Gitee 访问更流畅。

Ubuntu 下的包管理 / apt工具

包管理系统的功能和优点大致相同,但打包格式和工具会因平台(不同的 Linux 发行版)而异,如下表所示。

操作系统格式工具
Debian.debapt, apt-cache, apt-get, dpkg
Ubuntu.debapt, apt-cache, apt-get, dpkg
CentOS.rpmyum
Fedora.rpmdnf
FreeBSDPorts, .txzmake, pkg

一般来说 Ubuntu 下很多软件是需要先自行提供源码,使用源码自行编译,编译完成以后使用命令 “install” 来安装到系统中。当然 Ubuntu 下也有其它的软件安装方法,使用得最多的方法就是自行编译源码后进行安装,尤其是嵌入式 Linux 开发。

自行对软件源码编译的一个好处是可以针对不同平台进行编译和部署。

我们利用软件包管理系统可以直接下载并安装所有通过认证的软件,其中 Ubuntu 下我们用的最多的下载工具: APT 下载工具, APT 下载工具可以实现软件自动下载、配置、安装二进制或者源码的功能。 在我们使用 APT 工具下载安装或者更新软件的时候,首先会在下载列表中与本机软件进行对比,看一下需要下载哪些软件,或者升级哪些软件,默认情况下 APT 会下载并安装最新的软件包,被安装的软件包所依赖的其它软件也会被下载安装或者更新,非常智能省心。

包管理工具 apt

Linux apt 命令 | 菜鸟教程 (runoob.com)。

# "package" 替换为 包名。
sudo apt-get update                         更新源
sudo apt-get upgrade                        更新已安装的包
sudo apt-get install package                安装包
sudo apt-get remove package                 删除包
​
sudo apt-cache search package               搜索软件包
sudo apt-cache show package                 获取包的相关信息,例如说明、大小、脚本等
​
sudo apt-get install package --reinstall    重新安装包
sudo apt-get -f install                     修复安装
sudo apt-get remove package --purge         删除包,包括配置文件等
sudo apt-get build-dep package              安装相关的编译环境
sudo apt-get dist-upgrade                   升级系统
sudo apt-cache depends package              了解使用该包依赖那些包
sudo apt-cache rdepends package             查看该包被那些包依赖
sudo apt-get source package                 下载该包的源代码
换源 和 添加系统变量

换源

Ubuntu Ports更换成阿里云镜像源-阿里云开发者社区 (aliyun.com)。

  1. 首先备份源列表:sudo cp /etc/apt/sources.list /etc/apt/sources.list_backup

  2. 编辑 /etc/apt/sources.list 文件,在文件最前面添加镜像源:

    # 阿里源
    deb https://mirrors.aliyun.com/ubuntu-ports/ xenial main restricted universe multiverse
    deb https://mirrors.aliyun.com/ubuntu-ports/ xenial-updates main restricted universe multiverse
    deb https://mirrors.aliyun.com/ubuntu-ports/ xenial-backports main restricted universe multiverse
    deb https://mirrors.aliyun.com/ubuntu-ports/ xenial-security main restricted universe multiverse
    # 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 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 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 main restricted universe multiverse
    deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
    deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
    deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
    deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse# 中科大源
    deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
    deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
    deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
    deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
    deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
    deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
    deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
    deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
    deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
    deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
    ​
    # 163源
    deb http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
    deb http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
    deb http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
    deb http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
    deb http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
    deb-src http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
    deb-src http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
    deb-src http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
    deb-src http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
    deb-src http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
  3. 更新源:

    sudo apt update
    sudo apt upgrade

添加系统变量

  • 临时:终端中键入 export PATH=$PATH:<目录/要添加的系统变量>,重启后丢失。

  • 永久(只对当前用户有效):修改 ~/.bashrc 文件,在行尾添加 export PATH=$PATH:<目录/要添加的系统变量>,然后终端键入 source ~/.bashrc 使之生效,即可。

Ubuntu 下的卸载包

Ubuntu GUI 界面操作:

  • 使用 Synaptic 软件包管理器进行卸载。系统里面若没有 Synaptic Pack Manager 软件,则在终端安装 sudo apt-get install synaptic;具体使用方法。

  • 使用 Ubuntu 的软件中心进行卸载。略。

Ubuntu 终端里操作:

  • 列出所有软件包,以可翻页的形式:dpkg --list | less;以搜索特定包名的形式:dpkg --list | grep -n "python";还可以加通配符,很灵活。

  • 卸载程序和所有配置文件:sudo apt-get --purge remove <package-name>

  • 只卸载程序但保留配置文件:sudo apt-get remove <package-name>

  • 删除没用的依赖包:sudo apt-get autoremove <package-name>,加上 --purge 选项就是程序和配置文件都删除。资源不紧张时,此条慎用。

http://www.lryc.cn/news/228183.html

相关文章:

  • springcloudalibaba入门详细使用教程
  • C# DirectoryInfo类的用法
  • IDEA常用快捷键大全(详解)
  • 设计模式之解释器模式
  • 粉够荣获淘宝联盟区域理事会常务理事,携手共铸淘客新生态
  • Python爬虫是否合法?
  • 3.2 IDAPro脚本IDC常用函数
  • 用python将csv表格数据做成热力图
  • 【程序基础】递归法
  • AI 绘画 | Stable Diffusion WebUI的基本设置和插件扩展
  • 如何用自然语言 5 分钟构建个人知识库应用?我的 GPTs builder 尝试
  • rabbitmq启动异常解决
  • OpenGL_Learn08(坐标系统与3D空间)
  • github私有仓库开发,公开仓库发布版本
  • 绿色低碳 数字未来-辽宁省建筑电气2023年学术年会-安科瑞 蒋静
  • day55
  • 如何安装Node.js? 创建Vue脚手架
  • ASP.NETWeb开发(C#版)-day1-C#基础+实操
  • LGSVL Python API 使用
  • 详解数据仓库之拉链表(原理、设计以及在Hive中的实现)
  • 使用Nodejs搭建简单的web网页并实现公网访问
  • C++学习第三十七天----第十章--对象和类
  • TikTok影响力经济:解锁社交媒体的商业机遇
  • 燃气管网监测系统|全面保障燃气安全
  • 第三章:人工智能深度学习教程-基础神经网络(第六节-ML深度学习层列表)
  • 福建科立讯通信 指挥调度管理平台RCE漏洞复现
  • 性能测试:Jenkins+Ant+Jmeter自动化框架的搭建方法
  • 【开源项目】snakeflow流程引擎研究
  • 11.10 知识总结(数据的增删改查、如何创建表关系、Django框架的请求生命周期流程图)
  • AI脑控机器人应用前景如何?