Linux系统安装软件四种方式

2023年 11月 15日 60.5k 0

Linux系统安装软件四种方式:

  • 绿色安装
  • yum安装
  • rpm安装
  • 源码安装

图片[1]-Linux系统安装软件四种方式-不念博客

1. 绿色安装

这种方式最简便,一般提供Compressed Archive压缩文档包,如Java软件的压缩文档包,只需要解压、设置环境变量即可直接使用。

# 下载软件
https://www.oracle.com/java/technologies/downloads/

# 新建java软件存放路径
mkdir /opt/java

# 解压
tar -xvf jdk-21_linux-x64_bin.tar.gz -C /opt/java

# 设置环境变量
vim /etc/profile.d/java.sh

JAVA_HOME=/opt/java/jdk-21.0.1/
CLASSPATH=.:$JAVA_HOME/lib
PATH=JAVA_HOME/bin:$PATH
export JAVA_HOME CLASSPATH PATH

# 加载环境变量
source /etc/profile.d/java.sh

# 检验java环境是否配置好
java

2. yum安装

  • 前提条件是有网络
  • 需要安装的软件及版本,yum源里刚好有。
# 搜索redis源
yum search redis

# 查看redis详细信息
yum info redis

# 安装redis软件
yum -y install redis

# 查看redis状态
systemctl status redis

# 设置开机自启
systemctl enable redis

# 启动redis服务
systemctl start redis

3. rpm安装

需要的软件及版本,只提供了rpm包

3.1 rpm常用命令

# 安装一个包
rpm -ivh 包名

# 升级一个包
rpm -Uvh 包名

# 查询包是否安装
rpm -q 包名

# 查询安装包详情信息
rpm -qi 包名

# 列出服务器上的一个文件属于哪个rpm包
rpm -qf 文件名

# 列出所有安装的rpm包
rpm -qa

# 卸载包
rpm -e 包名
[root@centos ~]# rpm --help
Usage: rpm [OPTION...]

Query/Verify package selection options:
  -a, --all                        query/verify all packages
  -f, --file                       query/verify package(s) owning file
  -g, --group                      query/verify package(s) in group
  -p, --package                    query/verify a package file
  --pkgid                          query/verify package(s) with package identifier
  --hdrid                          query/verify package(s) with header identifier
  --triggeredby                    query the package(s) triggered by the package
  --whatrequires                   query/verify the package(s) which require a dependency
  --whatprovides                   query/verify the package(s) which provide a dependency
  --nomanifest                     do not process non-package files as manifests

Query options (with -q or --query):
  -c, --configfiles                list all configuration files
  -d, --docfiles                   list all documentation files
  -L, --licensefiles               list all license files
  --dump                           dump basic file information
  -l, --list                       list files in package
  --queryformat=QUERYFORMAT        use the following query format
  -s, --state                      display the states of the listed files

Verify options (with -V or --verify):
  --nofiledigest                   don't verify digest of files
  --nofiles                        don't verify files in package
  --nodeps                         don't verify package dependencies
  --noscript                       don't execute verify script(s)

Install/Upgrade/Erase options:
  --allfiles                       install all files, even configurations which might otherwise be skipped
  --allmatches                     remove all packages which match  (normally an error is generated if
                                    specified multiple packages)
  --badreloc                       relocate files in non-relocatable package
  -e, --erase=+           erase (uninstall) package
  --excludedocs                    do not install documentation
  --excludepath=             skip files with leading component  
  --force                          short hand for --replacepkgs --replacefiles
  -F, --freshen=+     upgrade package(s) if already installed
  -h, --hash                       print hash marks as package installs (good with -v)
  --ignorearch                     don't verify package architecture
  --ignoreos                       don't verify package operating system
  --ignoresize                     don't check disk space before installing
  -i, --install                    install package(s)
  --justdb                         update the database, but do not modify the filesystem
  --nodeps                         do not verify package dependencies
  --nofiledigest                   don't verify digest of files
  --nocontexts                     don't install file security contexts
  --noorder                        do not reorder package installation to satisfy dependencies
  --noscripts                      do not execute package scriptlet(s)
  --notriggers                     do not execute any scriptlet(s) triggered by this package
  --nocollections                  do not perform any collection actions
  --oldpackage                     upgrade to an old version of the package (--force on upgrades does this
                                   automatically)
  --percent                        print percentages as package installs
  --prefix=                   relocate the package to , if relocatable
  --relocate==           relocate files from path  to 
  --replacefiles                   ignore file conflicts between packages
  --replacepkgs                    reinstall if the package is already present
  --test                           don't install, but tell if it would work or not
  -U, --upgrade=+     upgrade package(s)
  --reinstall=+       reinstall package(s)

Common options for all rpm modes and executables:
  -D, --define='MACRO EXPR'        define MACRO with value EXPR
  --undefine=MACRO                 undefine MACRO
  -E, --eval='EXPR'                print macro expansion of EXPR
  --macros=              read  instead of default file(s)
  --noplugins                      don't enable any plugins
  --nodigest                       don't verify package digest(s)
  --nosignature                    don't verify package signature(s)
  --rcfile=              read  instead of default file(s)
  -r, --root=ROOT                  use ROOT as top level directory (default: "/")
  --dbpath=DIRECTORY               use database in DIRECTORY
  --querytags                      display known query tags
  --showrc                         display final rpmrc and macro configuration
  --quiet                          provide less detailed output
  -v, --verbose                    provide more detailed output
  --version                        print the version of rpm being used

Options implemented via popt alias/exec:
  --scripts                        list install/erase scriptlets from package(s)
  --setperms                       set permissions of files in a package
  --setugids                       set user/group ownership of files in a package
  --setcaps                        set capabilities of files in a package
  --restore                        restore file/directory permissions
  --conflicts                      list capabilities this package conflicts with
  --obsoletes                      list other packages removed by installing this package
  --provides                       list capabilities that this package provides
  --requires                       list capabilities required by package(s)
  --info                           list descriptive information from package(s)
  --changelog                      list change logs for this package
  --xml                            list metadata in xml
  --triggers                       list trigger scriptlets from package(s)
  --last                           list package(s) by install time, most recent first
  --dupes                          list duplicated packages
  --filesbypkg                     list all files from each package
  --fileclass                      list file names with classes
  --filecolor                      list file names with colors
  --fscontext                      list file names with security context from file system
  --fileprovide                    list file names with provides
  --filerequire                    list file names with requires
  --filecaps                       list file names with POSIX1.e capabilities

Help options:
  -?, --help                       Show this help message
  --usage                          Display brief usage message
# 安装java的jdk
rpm -ivh jdk-21_linux-x64_bin.rpm

# 查看安装的jdk
rpm -qa | grep "jdk"

# 忽略依赖关系强制卸载jdk
rpm -evh --nodeps jdk-21-21.0.1-12.x86_64

4. 源码安装

软件给的是C语言的源代码,需要编译成二进制,再安装。

Linux下安装软件,大型软件docker、oracle一般放/opt目录下;/usr目录一般由软件包管理器(yum、apt)来管理;/usr/local是用户级程序目录,/usr/local/src是用户级存放目录。

以安装nginx为例

# 安装依赖
yum install -y gcc pcre-devel openssl-devel

4.1 执行configure脚本

./configure [option…]
  • 通过选项传递参数,指定安装路径、启用特性等;执行时会参考用户的指定以及Makefile.in文件生成Makefile
  • 检查依赖到的外部环境,如依赖的软件包
tar -xvf nginx-1.25.3.tar.gz

cd nginx-1.25.3

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --user=nginx --group=nginx

选项说明:

选项 说明
–prefix=/usr/local/nginx 编译安装目录。如果没有指定,默认为 /usr/local/程序名
–user=nginx 所属用户nginx
–group=nginx 所属组nginx
–with-http_stub_status_module 该模块提供nginx的基本状态信息
–with-http_ssl_module 支持HTTPS

4.2 编译、安装

# 编译
make 
  • make 根据Makefile文件,会检测依赖的环境,进行构建应用程序

4.3 安装

# 安装
make install
  • make install 复制文件到相应路径

4.4 操作nginx

# 启动服务
/usr/local/nginx/sbin/nginx

# 重新加载配置文件
/usr/local/nginx/sbin/nginx -s reload

# 设置软连接
ln -s /usr/local/nginx/sbin/nginx  /usr/local/sbin/

# 强制停止
nginx -s stop

# 安全退出
nginx -s quit

# 查看进程
ps -ef | grep nginx

# 测试
curl 127.0.0.1

4.5 创建服务器

编写配置文件

# 编写配置文件
vi /usr/lib/systemd/system/nginx.service

# 写入这些信息
[Unit]
Description=nginx
After=network.target

[Service]
Type=forking
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target

使用systemctl管理nginx服务

systemctl enable nginx

systemctl strat nginx

systemctl status nginx

相关文章

服务器端口转发,带你了解服务器端口转发
服务器开放端口,服务器开放端口的步骤
产品推荐:7月受欢迎AI容器镜像来了,有Qwen系列大模型镜像
如何使用 WinGet 下载 Microsoft Store 应用
百度搜索:蓝易云 – 熟悉ubuntu apt-get命令详解
百度搜索:蓝易云 – 域名解析成功但ping不通解决方案

发布评论