如何在 Ubuntu Server 18.04 上将 sed 升级到 4.5?

Jus*_*ner 2 upgrade apt sed

我想sed在 Ubuntu Server 18.04 上尝试最新的实用程序。我试过下面的命令,但仍然无法升级它。我怎样才能做到这一点?

root@u1804:~# apt update
Hit:1 http://archive.ubuntu.com/ubuntu bionic InRelease
Get:2 http://archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:3 https://download.docker.com/linux/ubuntu bionic InRelease [64.4 kB]
Get:4 http://archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
Get:5 http://archive.ubuntu.com/ubuntu bionic-security InRelease [83.2 kB]
Fetched 311 kB in 7s (47.3 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
97 packages can be upgraded. Run 'apt list --upgradable' to see them.
root@u1804:~# 
root@u1804:~# apt show sed
Package: sed
Version: 4.4-2
Priority: required
Essential: yes
Section: utils
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Clint Adams <clint@debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 328 kB
Pre-Depends: libc6 (>= 2.14), libselinux1 (>= 1.32)
Homepage: https://www.gnu.org/software/sed/
Task: minimal
Supported: 5y
Download-Size: 182 kB
APT-Manual-Installed: yes
APT-Sources: http://archive.ubuntu.com/ubuntu bionic/main amd64 Packages
Description: GNU stream editor for filtering/transforming text
 sed reads the specified files or the standard input if no
 files are specified, makes editing changes according to a
 list of commands, and writes the results to the standard
 output.
root@u1804:~#
root@u1804:~# apt install --only-upgrade sed
Reading package lists... Done
Building dependency tree
Reading state information... Done
sed is already the newest version (4.4-2).
0 upgraded, 0 newly installed, 0 to remove and 97 not upgraded.
root@u1804:~#
Run Code Online (Sandbox Code Playgroud)

fkr*_*iem 6

注意:撰写本文时最新版本的 GNU sed 是 4.7,而不是 4.5。

这是一个替代选项:使用 GNU 源代码包的两个非常有用的功能,直接从源 tarball 编译。

  • 您可以使用sed您想要的任何其他名称安装新版本,这样它就不会干扰您当前的sed; 在这个答案中,我将使用sed47.
  • make uninstall支持该命令,如果您不再需要它,它允许您干净地卸载它。

首先安装所有构建依赖项

sudo apt-get build-dep sed
Run Code Online (Sandbox Code Playgroud)

获取源码并解压

cd
wget ftp://ftp.gnu.org/gnu/sed/sed-4.7.tar.xz
tar xf sed-4.7.tar.xz
rm sed-4.7.tar.xz    # optional
cd sed-4.7
Run Code Online (Sandbox Code Playgroud)

配置、构建和安装。注意--program-suffixto 参数configure,它告诉构建系统附加47到所有可执行文件的名称。

./configure --program-suffix=47
make
sudo make install
Run Code Online (Sandbox Code Playgroud)

您现在可以将新的 sed 与命令sed47一起使用man sed47,使用 等查阅其手册页。当/如果您想卸载它时,请执行

cd ~/sed-4.7
sudo make uninstall
Run Code Online (Sandbox Code Playgroud)

如果您已删除该sed-4.7目录,则可以通过重复上述安装说明(至少最多make)来重新创建它。

如果您想将其用作 sed 的“主要”版本,您可以创建一个别名:

alias sed=sed47
Run Code Online (Sandbox Code Playgroud)

在这种情况下,我建议订阅info-gnu 邮件列表以获取有关新版本的公告,其中可能包含重要的错误修复。