流编辑器 - 环境

本章介绍如何在GNU/Linux系统上设置SED环境.

使用软件包管理器安装

通常,SED是在大多数GNU/Linux发行版上默认可用.使用哪个命令来识别它是否存在于您的系统中.如果没有,那么使用 apt 包管理器在基于Debian的GNU/Linux上安装SED,如下所示:

[jerry] $ sudo apt-get install sed


安装后,确保可以通过命令行访问SED.

[jerry] $ sed --version


执行上述代码后,您会得到以下结果:

sed (GNU sed) 4.2.2 
Copyright (C) 2012 Free Software Foundation, Inc. 
License GPLv3+: GNU GPL version 3 or later. 
This is free software: you are free to change and redistribute it. 
There is NO WARRANTY, to the extent permitted by law.  
Written by Jay Fenlason, Tom Lord, Ken Pizzini, 
and Paolo Bonzini. 
GNU sed home page:. 
General help using GNU software:. 
E-mail bug reports to:. 
Be sure to include the word "sed" somewhere in the "Subject:" field.


同样,要在基于RPM的GNU/Linux上安装SED,请使用yum package manager,如下所示:

[root]# yum -y install sed


安装后,确保可以通过命令行访问SED.

[root]# sed --version


执行上述代码时,得到以下结果:

GNU sed version 4.2.1 
Copyright (C) 2009 Free Software Foundation, Inc. 
This is free software; see the source for copying conditions.  There is NO 
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, 
to the extent permitted by law.  
GNU sed home page:. 
General help using GNU software:. 
E-mail bug reports to:. 
Be sure to include the word "sed" somewhere in the "Subject:" field.


从源代码安装

由于GNU SED是GNU项目的一部分,因此其源代码可用于免费下载.我们已经看到了如何使用包管理器安装SED.现在让我们了解如何从源代码安装SED.

以下安装适用于任何GNU/Linux软件,以及大多数其他免费程序.以下是安装步骤:

  • 从真实位置下载源代码.命令行实用程序 wget 用于此目的.

  • [jerry]$ wget ftp://ftp.gnu.org/gnu/sed/sed-4.2.2.tar.bz2
  • 解压缩并解压缩下载的源代码.

  • [jerry] $ tar xvf sed-4.2.2.tar.bz2
  • 进入目录并运行configure.

  • [jerry] $ ./configure
  • 成功完成后, configure 会生成Makefile.要编译源代码,请发出 make 命令.

  • [jerry] $ make
  • 您可以运行测试套件以确保构建是干净的.这是一个可选步骤.

  • [jerry] $ make check
  • 最后,安装SED实用程序.确保你拥有超级用户权限.

  • [jerry] $ sudo make install

就是这样!您已成功编译并安装了SED.通过执行 sed 命令验证它,如下所示:

[jerry]$ sed --version

在执行上述代码时,您会得到以下结果:

sed (GNU sed) 4.2.2 
Copyright (C) 2012 Free Software Foundation, Inc. 
License GPLv3+: GNU GPL version 3 or later. 
This is free software: you are free to change and redistribute it. 
There is NO WARRANTY, to the extent permitted by law.  
Written by Jay Fenlason, Tom Lord, Ken Pizzini, 
and Paolo Bonzini. 
GNU sed home page:. 
General help using GNU software:. 
E-mail bug reports to:. 
Be sure to include the word "sed" somewhere in the "Subject:" field.