Ubuntu 更新apt源及apt常用命令

Ubuntu 更新apt源及apt常用命令

Ubuntu 更新apt源及常用命令

替换apt国内源更新软件包信息可更新的包信息更新所有包安装编译必备安装软件包查找软件包名查找包含文件的软件包名列出软件包的所有文件删除软件包

替换apt国内源

执行以下命令

mv -f /etc/apt/sources.list /etc/apt/sources.list.bak

cat > /etc/apt/sources.list<< EOF

deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse

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

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

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

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

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

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

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

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

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

EOF

把原来的apt源重命名为sources.list.bak,将阿里云的源作为apt默认使用的源 如果阿里云的源失效,则考虑执行以下命令恢复官方源

mv -f /etc/apt/sources.list.bak /etc/apt/sources.list

更新软件包信息

只更新不升级,已安装的软件包是否有可用的更新

apt update

显示如下则代表所有的包都是最新的,没有可以更新的。

Ign:1 http://mirrors.aliyun.com/ubuntu trusty InRelease

Hit:2 http://mirrors.aliyun.com/ubuntu trusty-security InRelease

Hit:3 http://mirrors.aliyun.com/ubuntu trusty-updates InRelease

Hit:4 http://mirrors.aliyun.com/ubuntu trusty-proposed InRelease

Hit:5 http://mirrors.aliyun.com/ubuntu trusty-backports InRelease

Hit:6 http://mirrors.aliyun.com/ubuntu trusty Release

Reading package lists... Done

Building dependency tree

Reading state information... Done

All packages are up to date.

显示如下则代表还有需要更新的包

224 packages can be upgraded. Run 'apt list --upgradable' to see them.

可更新的包信息

执行以下命令显示可更新包的具体信息

apt list --upgradable

apt自己的更新信息也在列表中

更新所有包

apt -y upgrade

直接将所有的包更新到最新,注意,这可能是个危险操作。 如果你的开发和生产环境依赖特殊版本,则需要使用以下命令升级指定某个包到特殊版本

apt upgrade xxx=1.0.0

安装编译必备

build-essential 是一个meta package,它依赖一篮子软件包,使用以下命令可以看到依赖关系

$ apt-cache depends build-essential

build-essential

|Depends: libc6-dev

Depends:

libc6-dev

Depends: gcc

Depends: g++

Depends: make

make-guile

Depends: dpkg-dev

gcc及make方式

apt install build-essential

使用cmake构建系统需要额外安装

apt install cmake

ninja取代make需要额外安装

apt install ninja-build

如果你使用的是更老的编译方式,那么执行以下命令

apt install autoconf # loads autoscan, autoconf and associated macros

apt install automake

apt install libtool

apt install m4

安装软件包

apt install golang

查找软件包名

apt-cache search golang

查找包含文件的软件包名

apt install apt-file

apt-file update

apt-file search lua.hpp

这个类似于centos的yum whatprovides 命令,查找返回以下结果

emscripten: /usr/share/emscripten/tests/lua/src/lua.hpp

liblua5.1-0-dev: /usr/include/lua5.1/lua.hpp

liblua5.2-dev: /usr/include/lua5.2/lua.hpp

liblua5.3-dev: /usr/include/lua5.3/lua.hpp

libluabind-dev: /usr/include/luabind/detail/convert_to_lua.hpp

libluajit-5.1-dev: /usr/include/luajit-2.1/lua.hpp

libtexlua52-dev: /usr/include/texlua52/lua.hpp

libtexluajit-dev: /usr/include/texluajit/lua.hpp

lua5.1-doc: /usr/share/doc/lua5.1-doc/etc/lua.hpp

tarantool-lts-dev: /usr/include/tarantool/lua.hpp

列出软件包的所有文件

apt-file list golang

删除软件包

apt remove golang