个人环境之ubuntu的apt-get 总结

原创
2020/02/28 01:32
阅读数 695

前言

apt-get是必须要学会的,如果搞定apt-get,可解决很多问题。接下来鸟才啊总结以往经验。

场景一 指定安装版本

先查看有软件有那些版本可以安装

apt-cache madison gcc-4.8

   gcc-4.8 | 4.8.5-4ubuntu8 | http://mirrors.aliyun.com/ubuntu bionic/universe amd64 Packages
   gcc-4.8 | 4.8.5-4ubuntu8 | http://mirrors.aliyun.com/ubuntu bionic/universe Sources
 
apt-get install -y gcc-4.8=4.8.5-4ubuntu8

场景二 查看那些软件可以安装

apt list  // 输出太多了

apt list | grep g++

场景三 安装gcc g++

安装gcc,g++ 太麻烦了。第一个是版本太多,第二个同软件的依赖的版本不同,第三没有搞清楚原理,浪费大量的时间。

先查gcc的版本
apt list  | grep "g++"

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

g++/bionic 4:7.3.0-3ubuntu2 amd64
g++-4.8/bionic,now 4.8.5-4ubuntu8 amd64 [已安装]
g++-4.8-multilib/bionic 4.8.5-4ubuntu8 amd64
g++-5/bionic 5.5.0-12ubuntu1 amd64
g++-5-aarch64-linux-gnu/bionic 5.5.0-12ubuntu1cross1 amd64
g++-5-alpha-linux-gnu/bionic 5.5.0-12ubuntu1cross1 amd64
g++-5-arm-linux-gnueabi/bionic 5.5.0-12ubuntu1cross1 amd64
g++-5-arm-linux-gnueabihf/bionic 5.5.0-12ubuntu1cross1 amd64
g++-5-i686-linux-gnu/bionic 5.5.0-12ubuntu1cross1 amd64
g++-5-m68k-linux-gnu/bionic 5.5.0-12ubuntu1cross1 amd64
g++-5-mips-linux-gnu/bionic 5.5.0-12ubuntu1cross1 amd64
g++-5-mips64-linux-gnuabi64/bionic 5.5.0-12ubuntu1cross1 amd64
g++-5-mips64el-linux-gnuabi64/bionic 5.5.0-12ubuntu1cross1 amd64
g++-5-mipsel-linux-gnu/bionic 5.5.0-12ubuntu1cross1 amd64
g++-5-multilib/bionic 5.5.0-12ubuntu1 amd64
g++-5-multilib-arm-linux-gnueabi/bionic 5.5.0-12ubuntu1cross1 amd64
g++-5-multilib-arm-linux-gnueabihf/bionic 5.5.0-12ubuntu1cross1 amd64
g++-5-multilib-i686-linux-gnu/bionic 5.5.0-12ubuntu1cross1 amd64
g++-5-multilib-mips-linux-gnu/bionic 5.5.0-12ubuntu1cross1 amd64
g++-5-multilib-mips64-linux-gnuabi64/bionic 5.5.0-12ubuntu1cross1 amd64
g++-5-multilib-mips64el-linux-gnuabi64/bionic 5.5.0-12ubuntu1cross1 amd64
g++-5-multilib-mipsel-linux-gnu/bionic 5.5.0-12ubuntu1cross1 amd64
g++-5-multilib-powerpc-linux-gnu/bionic 5.5.0-12ubuntu1cross1 amd64
g++-5-multilib-powerpc64-linux-gnu/bionic 5.5.0-12ubuntu1cross1 amd64
g++-5-multilib-s390x-linux-gnu/bionic 5.5.0-12ubuntu1cross1 amd64
g++-5-multilib-sparc64-linux-gnu/bionic 5.5.0-12ubuntu1cross1 amd64
g++-5-multilib-x86-64-linux-gnux32/bionic 5.5.0-12ubuntu1cross1 amd64
g++-5-powerpc-linux-gnu/bionic 5.5.0-12ubuntu1cross1 amd64
g++-5-powerpc-linux-gnuspe/bionic 5.5.0-12ubuntu1cross1 amd64
g++-5-powerpc64-linux-gnu/bionic 5.5.0-12ubuntu1cross1 amd64
g++-5-powerpc64le-linux-gnu/bionic 5.5.0-12ubuntu1cross1 amd64
g++-5-s390x-linux-gnu/bionic 5.5.0-12ubuntu1cross1 amd64
g++-5-sh4-linux-gnu/bionic 5.5.0-12ubuntu1cross1 amd64
g++-5-sparc64-linux-gnu/bionic 5.5.0-12ubuntu1cross1 amd64
g++-5-x86-64-linux-gnux32/bionic 5.5.0-12ubuntu1cross1 amd64
g++-6/bionic 6.4.0-17ubuntu1 amd64
g++-6-aarch64-linux-gnu/bionic 6.4.0-17ubuntu1cross1 amd64
g++-6-alpha-linux-gnu/bionic 6.4.0-17ubuntu1cross1 amd64
g++-6-arm-linux-gnueabi/bionic 6.4.0-17ubuntu1cross1 amd64
g++-6-arm-linux-gnueabihf/bionic 6.4.0-17ubuntu1cross1 amd64
g++-6-hppa-linux-gnu/bionic 6.4.0-17ubuntu1cross1 amd64
g++-6-i686-linux-gnu/bionic 6.4.0-17ubuntu1cross1 amd64
g++-6-m68k-linux-gnu/bionic 6.4.0-17ubuntu1cross1 amd64
g++-6-mips-linux-gnu/bionic 6.4.0-17ubuntu1cross1 amd64
g++-6-mips64-linux-gnuabi64/bionic 6.4.0-17ubuntu1cross1 amd64
g++-6-mips64el-linux-gnuabi64/bionic 6.4.0-17ubuntu1cross1 amd64
g++-6-mipsel-linux-gnu/bionic 6.4.0-17ubuntu1cross1 amd64
g++-6-multilib/bionic 6.4.0-17ubuntu1 amd64
g++-6-multilib-arm-linux-gnueabi/bionic 6.4.0-17ubuntu1cross1 amd64
g++-6-multilib-arm-linux-gnueabihf/bionic 6.4.0-17ubuntu1cross1 amd64
g++-6-multilib-i686-linux-gnu/bionic 6.4.0-17ubuntu1cross1 amd64
g++-6-multilib-mips-linux-gnu/bionic 6.4.0-17ubuntu1cross1 amd64
g++-6-multilib-mips64-linux-gnuabi64/bionic 6.4.0-17ubuntu1cross1 amd64
g++-6-multilib-mips64el-linux-gnuabi64/bionic 6.4.0-17ubuntu1cross1 amd64
g++-6-multilib-mipsel-linux-gnu/bionic 6.4.0-17ubuntu1cross1 amd64
g++-6-multilib-powerpc-linux-gnu/bionic 6.4.0-17ubuntu1cross1 amd64
g++-6-multilib-powerpc64-linux-gnu/bionic 6.4.0-17ubuntu1cross1 amd64
g++-6-multilib-s390x-linux-gnu/bionic 6.4.0-17ubuntu1cross1 amd64
g++-6-multilib-sparc64-linux-gnu/bionic 6.4.0-17ubuntu1cross1 amd64
g++-6-multilib-x86-64-linux-gnu/bionic 6.4.0-17ubuntu1cross1 i386
g++-6-multilib-x86-64-linux-gnux32/bionic 6.4.0-17ubuntu1cross1 amd64
g++-6-powerpc-linux-gnu/bionic 6.4.0-17ubuntu1cross1 amd64
g++-6-powerpc-linux-gnuspe/bionic 6.4.0-17ubuntu1cross1 amd64
g++-6-powerpc64-linux-gnu/bionic 6.4.0-17ubuntu1cross1 amd64
g++-6-powerpc64le-linux-gnu/bionic 6.4.0-17ubuntu1cross1 amd64
g++-6-s390x-linux-gnu/bionic 6.4.0-17ubuntu1cross1 amd64
g++-6-sh4-linux-gnu/bionic 6.4.0-17ubuntu1cross1 amd64
g++-6-sparc64-linux-gnu/bionic 6.4.0-17ubuntu1cross1 amd64
g++-6-x86-64-linux-gnu/bionic 6.4.0-17ubuntu1cross1 i386
g++-6-x86-64-linux-gnux32/bionic 6.4.0-17ubuntu1cross1 amd64
g++-7/bionic 7.3.0-16ubuntu3 amd64
g++-7-aarch64-linux-gnu/bionic 7.3.0-16ubuntu3cross1 amd64
g++-7-alpha-linux-gnu/bionic 7.3.0-16ubuntu3cross1 amd64
g++-7-arm-linux-gnueabi/bionic 7.3.0-16ubuntu3cross1 amd64
g++-7-arm-linux-gnueabihf/bionic 7.3.0-16ubuntu3cross1 amd64
g++-7-hppa-linux-gnu/bionic 7.3.0-16ubuntu3cross1 amd64
g++-7-i686-linux-gnu/bionic 7.3.0-16ubuntu3cross1 amd64
g++-7-m68k-linux-gnu/bionic 7.3.0-16ubuntu3cross1 amd64
g++-7-mips-linux-gnu/bionic 7.3.0-16ubuntu3cross1 amd64
g++-7-mips64-linux-gnuabi64/bionic 7.3.0-16ubuntu3cross1 amd64
g++-7-mips64el-linux-gnuabi64/bionic 7.3.0-16ubuntu3cross1 amd64
g++-7-mipsel-linux-gnu/bionic 7.3.0-16ubuntu3cross1 amd64
g++-7-multilib/bionic 7.3.0-16ubuntu3 amd64
g++-7-multilib-arm-linux-gnueabi/bionic 7.3.0-16ubuntu3cross1 amd64
g++-7-multilib-arm-linux-gnueabihf/bionic 7.3.0-16ubuntu3cross1 amd64
g++-7-multilib-i686-linux-gnu/bionic 7.3.0-16ubuntu3cross1 amd64
g++-7-multilib-mips-linux-gnu/bionic 7.3.0-16ubuntu3cross1 amd64
g++-7-multilib-mips64-linux-gnuabi64/bionic 7.3.0-16ubuntu3cross1 amd64
g++-7-multilib-mips64el-linux-gnuabi64/bionic 7.3.0-16ubuntu3cross1 amd64
g++-7-multilib-mipsel-linux-gnu/bionic 7.3.0-16ubuntu3cross1 amd64
g++-7-multilib-powerpc-linux-gnu/bionic 7.3.0-16ubuntu3cross1 amd64
g++-7-multilib-powerpc64-linux-gnu/bionic 7.3.0-16ubuntu3cross1 amd64
g++-7-multilib-s390x-linux-gnu/bionic 7.3.0-16ubuntu3cross1 amd64
g++-7-multilib-sparc64-linux-gnu/bionic 7.3.0-16ubuntu3cross1 amd64
g++-7-multilib-x86-64-linux-gnu/bionic 7.3.0-16ubuntu3cross1 i386
g++-7-multilib-x86-64-linux-gnux32/bionic 7.3.0-16ubuntu3cross1 amd64
g++-7-powerpc-linux-gnu/bionic 7.3.0-16ubuntu3cross1 amd64
g++-7-powerpc-linux-gnuspe/bionic 7.3.0-16ubuntu3cross1 amd64
g++-7-powerpc64-linux-gnu/bionic 7.3.0-16ubuntu3cross1 amd64
g++-7-powerpc64le-linux-gnu/bionic 7.3.0-16ubuntu3cross1 amd64
g++-7-riscv64-linux-gnu/bionic 7.3.0-16ubuntu3cross1 amd64
g++-7-s390x-linux-gnu/bionic 7.3.0-16ubuntu3cross1 amd64
g++-7-sh4-linux-gnu/bionic 7.3.0-16ubuntu3cross1 amd64
g++-7-sparc64-linux-gnu/bionic 7.3.0-16ubuntu3cross1 amd64
g++-7-x86-64-linux-gnu/bionic 7.3.0-16ubuntu3cross1 i386
g++-7-x86-64-linux-gnux32/bionic 7.3.0-16ubuntu3cross1 amd64
g++-8/bionic 8-20180414-1ubuntu2 amd64
g++-8-aarch64-linux-gnu/bionic 8-20180414-1ubuntu2cross1 amd64
g++-8-alpha-linux-gnu/bionic 8-20180414-1ubuntu2cross1 amd64
g++-8-arm-linux-gnueabi/bionic 8-20180414-1ubuntu2cross1 amd64
g++-8-arm-linux-gnueabihf/bionic 8-20180414-1ubuntu2cross1 amd64
g++-8-hppa-linux-gnu/bionic 8-20180414-1ubuntu2cross1 amd64
g++-8-i686-linux-gnu/bionic 8-20180414-1ubuntu2cross1 amd64
g++-8-m68k-linux-gnu/bionic 8-20180414-1ubuntu2cross1 amd64
g++-8-mips-linux-gnu/bionic 8-20180414-1ubuntu2cross1 amd64
g++-8-mips64-linux-gnuabi64/bionic 8-20180414-1ubuntu2cross1 amd64
g++-8-mips64el-linux-gnuabi64/bionic 8-20180414-1ubuntu2cross1 amd64
g++-8-mipsel-linux-gnu/bionic 8-20180414-1ubuntu2cross1 amd64
g++-8-multilib/bionic 8-20180414-1ubuntu2 amd64
g++-8-multilib-arm-linux-gnueabi/bionic 8-20180414-1ubuntu2cross1 amd64
g++-8-multilib-arm-linux-gnueabihf/bionic 8-20180414-1ubuntu2cross1 amd64
g++-8-multilib-i686-linux-gnu/bionic 8-20180414-1ubuntu2cross1 amd64
g++-8-multilib-mips-linux-gnu/bionic 8-20180414-1ubuntu2cross1 amd64
g++-8-multilib-mips64-linux-gnuabi64/bionic 8-20180414-1ubuntu2cross1 amd64
g++-8-multilib-mips64el-linux-gnuabi64/bionic 8-20180414-1ubuntu2cross1 amd64
g++-8-multilib-mipsel-linux-gnu/bionic 8-20180414-1ubuntu2cross1 amd64
g++-8-multilib-powerpc-linux-gnu/bionic 8-20180414-1ubuntu2cross1 amd64
g++-8-multilib-powerpc64-linux-gnu/bionic 8-20180414-1ubuntu2cross1 amd64
g++-8-multilib-s390x-linux-gnu/bionic 8-20180414-1ubuntu2cross1 amd64
g++-8-multilib-sparc64-linux-gnu/bionic 8-20180414-1ubuntu2cross1 amd64
g++-8-multilib-x86-64-linux-gnu/bionic 8-20180414-1ubuntu2cross1 i386
g++-8-multilib-x86-64-linux-gnux32/bionic 8-20180414-1ubuntu2cross1 amd64
g++-8-powerpc-linux-gnu/bionic 8-20180414-1ubuntu2cross1 amd64
g++-8-powerpc-linux-gnuspe/bionic 8-20180414-1ubuntu2cross1 amd64
g++-8-powerpc64-linux-gnu/bionic 8-20180414-1ubuntu2cross1 amd64
g++-8-powerpc64le-linux-gnu/bionic 8-20180414-1ubuntu2cross1 amd64
g++-8-riscv64-linux-gnu/bionic 8-20180414-1ubuntu2cross1 amd64
g++-8-s390x-linux-gnu/bionic 8-20180414-1ubuntu2cross1 amd64
g++-8-sh4-linux-gnu/bionic 8-20180414-1ubuntu2cross1 amd64
g++-8-sparc64-linux-gnu/bionic 8-20180414-1ubuntu2cross1 amd64
g++-8-x86-64-linux-gnu/bionic 8-20180414-1ubuntu2cross1 i386
g++-8-x86-64-linux-gnux32/bionic 8-20180414-1ubuntu2cross1 amd64
g++-aarch64-linux-gnu/bionic 4:7.3.0-3ubuntu2 amd64
g++-alpha-linux-gnu/bionic 4:7.3.0-3ubuntu1 amd64
g++-arm-linux-gnueabi/bionic 4:7.3.0-3ubuntu2 amd64
g++-arm-linux-gnueabihf/bionic 4:7.3.0-3ubuntu2 amd64
g++-hppa-linux-gnu/bionic 4:7.3.0-3ubuntu1 amd64
g++-i686-linux-gnu/bionic 4:7.3.0-3ubuntu2 amd64
g++-m68k-linux-gnu/bionic 4:7.3.0-3ubuntu1 amd64
g++-mingw-w64/bionic,bionic 7.3.0-11ubuntu1+20.2build1 all
g++-mingw-w64-i686/bionic 7.3.0-11ubuntu1+20.2build1 amd64
g++-mingw-w64-x86-64/bionic 7.3.0-11ubuntu1+20.2build1 amd64
g++-mips-linux-gnu/bionic 4:7.3.0-3ubuntu1 amd64
g++-mips64-linux-gnuabi64/bionic 4:7.3.0-3ubuntu1 amd64
g++-mips64el-linux-gnuabi64/bionic 4:7.3.0-3ubuntu1 amd64
g++-mipsel-linux-gnu/bionic 4:7.3.0-3ubuntu1 amd64
g++-multilib/bionic 4:7.3.0-3ubuntu2 amd64
g++-multilib-arm-linux-gnueabi/bionic 4:7.3.0-3ubuntu2 amd64
g++-multilib-arm-linux-gnueabihf/bionic 4:7.3.0-3ubuntu2 amd64
g++-multilib-i686-linux-gnu/bionic 4:7.3.0-3ubuntu2 amd64
g++-multilib-mips-linux-gnu/bionic 4:7.3.0-3ubuntu1 amd64
g++-multilib-mips64-linux-gnuabi64/bionic 4:7.3.0-3ubuntu1 amd64
g++-multilib-mips64el-linux-gnuabi64/bionic 4:7.3.0-3ubuntu1 amd64
g++-multilib-mipsel-linux-gnu/bionic 4:7.3.0-3ubuntu1 amd64
g++-multilib-powerpc-linux-gnu/bionic 4:7.3.0-3ubuntu2 amd64
g++-multilib-powerpc64-linux-gnu/bionic 4:7.3.0-3ubuntu1 amd64
g++-multilib-s390x-linux-gnu/bionic 4:7.3.0-3ubuntu2 amd64
g++-multilib-sparc64-linux-gnu/bionic 4:7.3.0-3ubuntu1 amd64
g++-multilib-x86-64-linux-gnu/bionic 4:7.3.0-3ubuntu2 i386
g++-multilib-x86-64-linux-gnux32/bionic 4:7.3.0-3ubuntu1 amd64
g++-powerpc-linux-gnu/bionic 4:7.3.0-3ubuntu2 amd64
g++-powerpc-linux-gnuspe/bionic 4:7.3.0-3ubuntu1 amd64
g++-powerpc64-linux-gnu/bionic 4:7.3.0-3ubuntu1 amd64
g++-powerpc64le-linux-gnu/bionic 4:7.3.0-3ubuntu2 amd64
g++-riscv64-linux-gnu/bionic 4:7.3.0-3ubuntu1 amd64
g++-s390x-linux-gnu/bionic 4:7.3.0-3ubuntu2 amd64
g++-sh4-linux-gnu/bionic 4:7.3.0-3ubuntu1 amd64
g++-sparc64-linux-gnu/bionic 4:7.3.0-3ubuntu1 amd64
g++-x86-64-linux-gnu/bionic 4:7.3.0-3ubuntu2 i386
g++-x86-64-linux-gnux32/bionic 4:7.3.0-3ubuntu1 amd64

查询可以安装的g++软件太多了。待鸟菜啊给你解释下:g++{?}, ?= 版本。g++或者gcc有太多版本了,其他软件对他们的版本非常敏感所以每个版本对应一个软件。比如g++8 就是g++ 第八个版本的编译器。可以把所有编译器下载下来,方便切换。

安装
niaocai:~/.local/share/applications$ ll /usr/bin/gcc*
lrwxrwxrwx 1 root root      5 2月  11  2016 /usr/bin/gcc -> gcc-5*
-rwxr-xr-x 1 root root 772280 3月  19  2018 /usr/bin/gcc-4.8*
-rwxr-xr-x 1 root root 915736 8月  28  2018 /usr/bin/gcc-5*
lrwxrwxrwx 1 root root      8 2月  11  2016 /usr/bin/gcc-ar -> gcc-ar-5*
-rwxr-xr-x 1 root root  27088 3月  19  2018 /usr/bin/gcc-ar-4.8*
-rwxr-xr-x 1 root root  31136 8月  28  2018 /usr/bin/gcc-ar-5*
lrwxrwxrwx 1 root root      8 2月  11  2016 /usr/bin/gcc-nm -> gcc-nm-5*
-rwxr-xr-x 1 root root  27088 3月  19  2018 /usr/bin/gcc-nm-4.8*
-rwxr-xr-x 1 root root  31136 8月  28  2018 /usr/bin/gcc-nm-5*
lrwxrwxrwx 1 root root     12 2月  11  2016 /usr/bin/gcc-ranlib -> gcc-ranlib-5*
-rwxr-xr-x 1 root root  27088 3月  19  2018 /usr/bin/gcc-ranlib-4.8*
-rwxr-xr-x 1 root root  31136 8月  28  2018 /usr/bin/gcc-ranlib-5*

已经存在gcc-4.8与gcc-5两个版本的存在,同时大家看到/usr/bin/gcc 是一个软连接,指向gcc-5。目前的gcc 是第五个版本的编译器。

  1. 改变gcc的软连接
  2. 使用gcc-5 这样指定编译器。比如修改eclipse的默认编译器是gcc-5

场景 关于源的问题

源是指:apt-get以及相关命令获得数据的地方。比如下载地址,依赖信息等。

源地址解读

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
  1. deb 与deb-src是指源类型。两个组成一个对。
  2. http://mirrors.aliyun.com/ubuntu/ 源地址
  3. bionic是版本别名(bionic是ubuntu18.04的别名,每个版本一个别名)。
  4. bionic bionic-security, bionic-updates,bionic-backports,bionic-proposed

    不同类型的源,缺一不可,且少一个就无法解决依赖关系等。所以每次修改源必须有十条数据

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

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

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

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

deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
展开阅读全文
加载中

作者的其它热门文章

打赏
0
0 收藏
分享
打赏
2 评论
0 收藏
0
分享
返回顶部
顶部