一、依赖包安装
1.1 离线安装
在无网环境部署服务器时,需要离线安装很多软件,如gcc
, cmake
,tmux
等,这时就要提前在有网环境下下载离线安装包。
有的软件只需要一个单独的deb
包安装即可,如net-tools
,而有的软件有很多的依赖包,如gcc
,这时就需要一个简单的方法来批量下载所有依赖deb
包。
这里以在ubuntu
系统安装cmake
为例,介绍如何安装cmake
,首先检查包是否已经安装。
以下两条命令均可以检查包是否已经安装:
root@rk3399:/opt# dpkg -l | grep cmake
root@rk3399:/opt# apt list --installed | grep cmake
1.1.1 查看依赖
这里以cmake
为例:
root@rk3399:/opt# apt-cache depends cmake
cmake
Depends: libarchive13
Depends: libc6
Depends: libcurl4
Depends: libexpat1
Depends: libgcc-s1
Depends: libjsoncpp25
Depends: librhash0
Depends: libstdc++6
Depends: libuv1
Depends: zlib1g
Depends: cmake-data
Depends: procps
Recommends: gcc
Recommends: make
make-guile
Suggests: cmake-doc
Suggests: ninja-build
Suggests: cmake-format
1.1.2 下载deb
及其依赖包
下载deb
有两种方式,第一种方式是在服务器通过命令在线下载;
root@rk3399:/opt# mkdir cmake
root@rk3399:/opt# cd cmake
root@rk3399:/opt/cmake# apt-get download $(apt-cache depends --recurse --no-recommends --no-suggests --no-conflicts --no-breaks --no-replaces --no-enhances --no-pre-depends cmake | grep "^\w")xxxxxxxxxx root@rk3399:/opt# mkdir cmakeroot@rk3399:/opt# cd cmakeroot@rk3399:/opt/cmake# apt-get download $(apt-cache depends --recurse --no-recommends --no-suggests --no-conflicts --no-breaks --no-replaces --no-enhances --no-pre-depends cmake | grep "^\w")apt-get download $(apt-cache depends --recurse --no-recommends --no-suggests --no-conflicts --no-breaks --no-replaces --no-enhances --no-pre-depends cmake | grep "^\w")
root@rk3399:/opt/cmake# ls
cdebconf_0.261ubuntu1_arm64.deb libgnutls30_3.7.3-4ubuntu1.2_arm64.deb librtmp1_2.4+20151223.gitfa8646d.1-2build4_arm64.deb
cmake-data_3.22.1-1ubuntu1.22.04.1_all.deb libgssapi-krb5-2_1.19.2-2ubuntu0.2_arm64.deb libsasl2-2_2.1.27+dfsg2-3ubuntu1.2_arm64.deb
cmake_3.22.1-1ubuntu1.22.04.1_arm64.deb libhogweed6_3.7.3-1build2_arm64.deb libsasl2-modules-db_2.1.27+dfsg2-3ubuntu1.2_arm64.deb
debconf_1.5.79ubuntu1_all.deb libicu70_70.1-2ubuntu1_arm64.deb libselinux1_3.3-1build2_arm64.deb
dh-elpa-helper_2.0.9ubuntu1_all.deb libidn2-0_2.3.2-2build1_arm64.deb libslang2_2.3.2-5build4_arm64.deb
dpkg_1.21.1ubuntu2.2_arm64.deb libjsoncpp25_1.9.5-3_arm64.deb libssh-4_0.9.6-2ubuntu0.22.04.1_arm64.deb
emacsen-common_3.0.4_all.deb libk5crypto3_1.19.2-2ubuntu0.2_arm64.deb libssl3_3.0.2-0ubuntu1.10_arm64.deb
gcc-12-base_12.3.0-1ubuntu1~22.04_arm64.deb libkeyutils1_1.6.1-2ubuntu3_arm64.deb libstdc++6_12.3.0-1ubuntu1~22.04_arm64.deb
init-system-helpers_1.62_all.deb libkrb5-3_1.19.2-2ubuntu0.2_arm64.deb libsystemd0_249.11-0ubuntu3.11_arm64.deb
libacl1_2.3.1-1_arm64.deb libkrb5support0_1.19.2-2ubuntu0.2_arm64.deb libtasn1-6_4.18.0-4build1_arm64.deb
libarchive13_3.6.0-1ubuntu1_arm64.deb libldap-2.5-0_2.5.16+dfsg-0ubuntu0.22.04.1_arm64.deb libtextwrap1_0.1-15build1_arm64.deb
libbrotli1_1.0.9-2build6_arm64.deb liblz4-1_1.9.3-2build2_arm64.deb libtinfo6_6.3-2ubuntu0.1_arm64.deb
libbz2-1.0_1.0.8-5build1_arm64.deb liblzma5_5.2.5-2ubuntu1_arm64.deb libunistring2_1.0-1_arm64.deb
libc6_2.35-0ubuntu3.4_arm64.deb libncurses6_6.3-2ubuntu0.1_arm64.deb libuv1_1.43.0-1_arm64.deb
libcom-err2_1.46.5-2ubuntu1.1_arm64.deb libncursesw6_6.3-2ubuntu0.1_arm64.deb libxml2_2.9.13+dfsg-1ubuntu0.3_arm64.deb
libcrypt1_1%3a4.4.27-1_arm64.deb libnettle8_3.7.3-1build2_arm64.deb libzstd1_1.4.8+dfsg-3build1_arm64.deb
libcurl4_7.81.0-1ubuntu1.14_arm64.deb libnewt0.52_0.52.21-5ubuntu2_arm64.deb lsb-base_11.1.0ubuntu4_all.deb
libdb5.3_5.3.28+dfsg1-0.8ubuntu3_arm64.deb libnghttp2-14_1.43.0-1build3_arm64.deb perl-base_5.34.0-3ubuntu1.2_arm64.deb
libdebian-installer4_0.122ubuntu3_arm64.deb libp11-kit0_0.24.0-6build1_arm64.deb procps_2%3a3.3.17-6ubuntu2_arm64.deb
libexpat1_2.4.7-1ubuntu0.2_arm64.deb libpcre2-8-0_10.39-3ubuntu0.1_arm64.deb tar_1.34+dfsg-1ubuntu0.1.22.04.1_arm64.deb
libffi8_3.4.2-4_arm64.deb libprocps8_2%3a3.3.17-6ubuntu2_arm64.deb zlib1g_1%3a1.2.11.dfsg-2ubuntu9.2_arm64.deb
libgcc-s1_12.3.0-1ubuntu1~22.04_arm64.deb libpsl5_0.21.0-1.2build2_arm64.deb
libgmp10_2%3a6.2.1+dfsg-3ubuntu1_arm64.deb librhash0_1.4.2-1ubuntu1_arm64.deb
此外,我们还可以通过ubuntu
镜像源下载:
https://ubuntu.pkgs.org/
;https://packages.ubuntu.com/
;https://mirrors.aliyun.com/ubuntu/pool/main//
;
比如cmake_3.22.1-1ubuntu1.22.04.1_arm64.deb
:
我们可以点击链接跳转到这个页面,在这个页面内可以看到如下信息:
-
Description
:当前包的描述信息; -
Requires
:依赖的包; -
Download
:下载地址; -
Install Howto
:如何通过apt
命令安装; -
Files
:当前包安装的文件以及安装路径;
1.1.3 使用dpkg
命令离线安装
root@rk3399:/opt/cmake# sudo dpkg -i *.deb
1.2 在线安装
1.2.1 默认版本安装
首先查看默认安装的版本:
root@rk3399:/opt/# apt show cmake
Package: cmake
Version: 3.22.1-1ubuntu1.22.04.1
Priority: optional
Section: devel
Origin: Ubuntu
Maintainer: Ubuntu Developers <[email protected]>
Original-Maintainer: Debian CMake Team <[email protected]>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 17.8 MB
Depends: libarchive13 (>= 3.3.3), libc6 (>= 2.34), libcurl4 (>= 7.16.2), libexpat1 (>= 2.0.1), libgcc-s1 (>= 3.3.1), libjsoncpp25 (>= 1.9.5), librhash0 (>= 1.2.6), libstdc++6 (>= 12), libuv1 (>= 1.38.0), zlib1g (>= 1:1.1.4), cmake-data (= 3.22.1-1ubuntu1.22.04.1), procps
Recommends: gcc, make
Suggests: cmake-doc, ninja-build, cmake-format
Homepage: https://cmake.org/
Download-Size: 4650 kB
APT-Sources: http://mirrors.huaweicloud.com/ubuntu-ports jammy-updates/main arm64 Packages
Description: cross-platform, open-source make system
CMake is used to control the software compilation process using
simple platform and compiler independent configuration files. CMake
generates native makefiles and workspaces that can be used in the
compiler environment of your choice. CMake is quite sophisticated: it
is possible to support complex environments requiring system
configuration, pre-processor generation, code generation, and template
instantiation.
.
CMake was developed by Kitware as part of the NLM Insight
Segmentation and Registration Toolkit project. The ASCI VIEWS project
also provided support in the context of their parallel computation
environment. Other sponsors include the Insight, VTK, and VXL open
source software communities.
N: There is 1 additional record. Please use the '-a' switch to see it
接着运行安装命令开始安装:
# Update the package index
root@rk3399:/opt# sudo apt-get update
# Install cmake deb package
root@rk3399:/opt#sudo apt-get install cmake
1.2.2 安装指定版本
比如我们想在ubuntu 22.04
版本下安装其它版本,可以到《https://ubuntu.pkgs.org/
》查找是否存在其他版本的deb
,如果有的话,可以点击相应链接跳转到包信息页面,在Install Howto
中获取安装命令:
# Update the package index:
root@rk3399:/opt#sudo apt-get update
# Install cmake-qt-gui deb package:
root@rk3399:/opt# sudo apt-get install cmake-qt-gui
当然如果安装的版本的deb
包在ubuntu
镜像源中无法找到,那么可以考虑源码编译安装。