有些情況下需要使用最新的dpkg或rpm。官方源裏提供的基本都是距離現在一到三年的穩定版本,想用最新的必須下載源碼編譯。
公共環境
安裝自動化編譯工具
sudo apt-get install autoconf autopoint automake libtool
dpkg
下載dpkg源碼
git clone https://git.dpkg.org/git/dpkg/dpkg.git
cd dpkg
安裝依賴庫sudo apt-get install libncurses5-dev
直接執行./autogen
如果報錯:
autopoint:*** gettext version 0.19.8 or newer is required
解決方案如下:這個報錯是版本校驗有問題,但是Ubuntu源裏最新的就是0.19.7了,所以我這裏修改如果失敗的話,不打印報錯,而是和校驗成功執行相同的代碼,親測無傷大雅。
直接打開
/usr/bin/autopoint
,修改代碼。這是一個腳本,在大約340行左右,找到代碼:if test -n "$xreq"; then if func_version_prereq "$xreq" "$archive_version"; then ver="$archive_version" else ver="$archive_version" # 複製if下的這一行到else這裏 # 把下面這一行直接註釋掉!!!!!!! # func_fatal_error "gettext version $xreq or newer is required" fi else if test -z "$xver" && test -f intl/VERSION; then xver=`cat intl/VERSION | LC_ALL=C sed -n -e 's/^.*gettext-\([-+_.0-9A-Za-z]*\).*$/\1/p'` fi
成功後生成configure
文件,直接./configure
可能會報錯perl
必須 >= 5.24.1
源內最新版本是5.22
,可以從官網下最新的版本然後編譯安裝。
wget https://www.cpan.org/src/5.0/perl-5.30.1.tar.gz
tar zxvf perl-5.30.1.tar.gz
cd perl-5.30.1/
./Configure
# 過程中出現問詢直接一路回車到底
# 遇到prefix輸入/usr回車。 默認會安裝到/usr/local。
# 那樣的話在make install之後還要手動創建軟連接直到新版本
# 才能讓dpkg的configure通過。
make
sudo make install
成功後生成Makefile
,執行make
如果需要安裝到系統目錄中,執行sudo make install
rpm
下載rpm源碼
git clone https://github.com/rpm-software-management/rpm.git
cd rpm
下載安裝依賴庫:
sudo apt-get install libnss3-dev libnspr4-dev zlib1g-dev libgcrypt20-dev libgcrypt20 libmagic-dev libdb-dev libpopt-dev libarchive-dev lua5.2 liblua5.2-dev liblzma-dev
修改配置腳本vi autogen.sh
爲:
#!/bin/sh
export CPPFLAGS
export CFLAGS="-I/usr/include/lua5.2 -I/usr/include/nspr -I/usr/include/nss"
export LDFLAGS="-llua5.2"
export LUA_LIBS="-I/usr/lib64"
export LUA_CFLAGS="-I/usr/bin"
autoreconf -i
sed -i "s/sysconfdir='\${prefix}\/etc'/sysconfdir='\/etc'/g" ./configure # 自動生成的configure文件中,sysconfdir的路徑指定的是{$prefix}/etc,打包的時候會有問題,應該改爲/etc
case "$1" in
"--noconfigure")
exit 0;
;;
"--rpmconfigure")
shift
eval "`rpm --eval %configure`" "$@"
;;
*)
./configure "$@" --prefix="/usr" # /usr 是安裝的路徑,不改的話默認爲/usr/local
;;
esac
執行./autogen.sh
完後彆着急編譯,打開生成的configure
文件1073行:
將sysconfdir={prefix}/etc
改成/etc
然後再次執行./autogen.sh
成功後生成Makefile
編譯安裝
make
sudo make install
安裝舊版的rpm(4.12)會出現問題db的問題的處理:
下載舊版的rpm
:
wget https://github.com/rpm-software-management/rpm/archive/rpm-4.12.0.1-release.tar.gz
tar zxvf rpm-4.12.0.1-release.tar.gz
cd rpm-4.12.0.1-release/
修改autogen.sh
,內容和上面一樣。然後執行./autogen.sh
然而報錯:
configure: error: internal Berkeley DB directory not present, see INSTALL
報錯已經提到了see INSTALL
,查看INSTALL
文件之內的內容,給出了兩個解決方案。按照給出的方案即可解決編譯。
修改autogen.sh
爲:
#!/bin/sh
export CPPFLAGS="-I/usr/include/db45"
export CFLAGS="-I/usr/include/lua5.2 -I/usr/include/nspr -I/usr/include/nss"
export LDFLAGS="-llua5.2"
export LUA_LIBS="-I/usr/lib64"
export LUA_CFLAGS="-I/usr/bin"
autoreconf -i
case "$1" in
"--noconfigure")
exit 0;
;;
"--rpmconfigure")
shift
eval "`rpm --eval %configure`" "$@"
;;
*)
./configure "$@" --prefix="/usr" --with-external-db
;;
esac