Linux軟體包轉換-deb與rpm互轉

坐公交也用券發表於2020-10-26

前言:
Linux二進位制軟體包分為幾大派系,其中deb與rpm為主流派。各個派系之間資源各有差異

1、工具安裝

1.1、apt安裝

apt系預設收錄該軟體,所以直接執行下面的安裝命令即可

apt install -y alien

1.2、yum安裝

由於yum系官方未收錄該軟體,所以需要先新增源再進行安裝,命令步驟如下:

yum install -y epel-release
rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm

然後更新源(可選)

yum update

最後是安裝

yum install  -y alien

1.3、安裝完成

執行下面的命令進行驗證是否安裝成功

[root@localhost ~]# alien -V
alien version 8.95

2、實踐操作

2.1、語法解析

直接執行下面的命令即可調出幫助命令

alien

結果如下:

[root@localhost ~]# alien
You must specify a file to convert.

Usage: alien [options] file [...]
  file [...]                Package file or files to convert.
  -d, --to-deb              Generate a Debian deb package (default).
     Enables these options:
       --patch=<patch>      Specify patch file to use instead of automatically
                            looking for patch in /var/lib/alien.
       --nopatch	    Do not use patches.
       --anypatch           Use even old version os patches.
       -s, --single         Like --generate, but do not create .orig
                            directory.
       --fixperms           Munge/fix permissions and owners.
       --test               Test generated packages with lintian.
  -r, --to-rpm              Generate a Red Hat rpm package.
      --to-slp              Generate a Stampede slp package.
  -l, --to-lsb              Generate a LSB package.
  -t, --to-tgz              Generate a Slackware tgz package.
     Enables these options:
       --description=<desc> Specify package description.
       --version=<version>  Specify package version.
  -p, --to-pkg              Generate a Solaris pkg package.
  -i, --install             Install generated package.
  -g, --generate            Generate build tree, but do not build package.
  -c, --scripts             Include scripts in package.
      --target=<arch>       Set architecture of the generated package.
  -v, --verbose             Display each command alien runs.
      --veryverbose         Be verbose, and also display output of run commands.
  -k, --keep-version        Do not change version of generated package.
      --bump=number         Increment package version by this number.
  -h, --help                Display this help message.
  -V, --version		    Display alien's version number.

從上面的資訊可以看出,常用的兩個引數為:

  • -d #轉為deb
  • -r #轉為rpm

2.2、rpm轉deb

首先使用下面的命令下載一個rpm包

yum install  --downloadonly vsftpd  --downloaddir=/opt/
 cd /opt;ls

執行過程:

[root@localhost ~]# yum install  --downloadonly vsftpd  --downloaddir=/opt/
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.aliyun.com
 * nux-dextop: li.nux.ro
 * updates: mirrors.ustc.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package vsftpd.x86_64 0:3.0.2-27.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================
 Package           Arch              Version                 Repository       Size
===================================================================================
Installing:
 vsftpd            x86_64            3.0.2-27.el7            base            172 k

Transaction Summary
===================================================================================
Install  1 Package

Total download size: 172 k
Installed size: 353 k
Background downloading packages, then exiting:
vsftpd-3.0.2-27.el7.x86_64.rpm                              | 172 kB  00:00:00     
exiting because "Download Only" specified
[root@localhost ~]# cd /opt;ls
vsftpd-3.0.2-27.el7.x86_64.rpm
[root@localhost opt]# 

然後使用下面的命令進行轉換

alien -d vsftpd-3.0.2-27.el7.x86_64.rpm

執行結果如下:

[root@localhost opt]# alien -d vsftpd-3.0.2-27.el7.x86_64.rpm 
Warning: Skipping conversion of scripts in package vsftpd: postinst postrm prerm
Warning: Use the --scripts parameter to include the scripts.
Can't exec "gcc": No such file or directory at /usr/share/perl5/vendor_perl/Dpkg/Arch.pm line 165.
dpkg-architecture: warning: cannot determine CC system type, falling back to default (native compilation)
vsftpd_3.0.2-28_amd64.deb generated
[root@localhost opt]# ls
vsftpd-3.0.2-27.el7.x86_64.rpm  vsftpd_3.0.2-28_amd64.deb

2.3、deb轉rpm

使用下面的命令進行轉換

[root@localhost opt]# rm -f vsftpd-3.0.2-27.el7.x86_64.rpm 
[root@localhost opt]# alien -r vsftpd_3.0.2-28_amd64.deb 
vsftpd-3.0.2-29.x86_64.rpm generated
[root@localhost opt]# ls
vsftpd_3.0.2-28_amd64.deb  vsftpd-3.0.2-29.x86_64.rpm

教程結束!!

相關文章