Linux源码安装软件

Linux环境下 源码编译安装软件

==== 1. 下载,步骤略

==== 2. 验证,部分官方下载同时提供签名,MD5,sha1,sha256等校验信息。

$ gpg --verify gnupg-2.2.14.tar.bz2.sig gnupg-2.2.14.tar.bz2 

$ md5sum archlinux-2019.03.01-x86_64.iso
8164667750c46cf297720b21145e1e27 archlinux-2019.03.01-x86_64.iso
$ sha1sum archlinux-2019.03.01-x86_64.iso
e32acb5a7b7cfb2bdba10697cce48ab69e13c186 archlinux-2019.03.01-x86_64.iso
查看得出的校验码是否与官方提供的信息一致。

$ md5sum -c twrp-3.1.1-1-libra.img.md5
twrp-3.1.1-1-libra.img: OK
$ sha256sum -c twrp-3.1.1-1-libra.img.sha256
twrp-3.1.1-1-libra.img: OK
直接使用官网提供校验文件验证。

==== 3. 查看 自述文件 README,安装说明 INSTALL 等文件信息。官网上有无特别安装要求等。

==== 4. 解包 tar,释放出源代码文件
$ tar zxvf xxx.tar.gz    xxx.tgz  //gzip压缩的tarball  
$ tar jxvf xxx.tar.bz2    //bzip2压缩的tarball文件

==== 5. 配置 ./configure 针对当前系统、软件环境,配置好安装参数,生成Makefile 
执行“./configure --help” 可以查看帮助
--prefix=软件安装目录 (若不指定任何配置选项,将采用默认值)
$ ./configure --prefix=/usr/local/xxx or///opt/XXX...

==== 6. 编译 make 将源代码文件变为二进制的可执行程序
$ make 

==== 7. 编译检测
$ make check 

==== 8. 安装 make install 将编译好的程序文件复制到系统中
$ sudo make install 

==== 9. 清理 make clean 用来清除编译连接过程中的一些临时文件
$ make clean

==== 10. 清理 make uninstall 用来卸载相关应用程序,
$ make uninstall

若无异常,按上述步骤安装即可。若遇到问题可继续往下看。
===============================

补充说明:

a. 安装环境可能需要手动安装gcc,make等软件包,按照Linux支持的安装命令安装即可。或者yum -y groupinstall "Development Tools" 自动安装基本开发工具。

b. $ ./configure --prefix=/指定路径:这里可以手动指定安装路径,或者使用配置文件默认的路径

大部分典型的 Linux 发行版的文件系统层次结构都遵从 文件系统层次化标准(FHS)

新软件默认安装在系统的 /usr/local 目录中。
这是依据 FHS 中 “/usr/local 层级是为系统管理员本地安装软件时使用的,它在系统软件更新覆盖时是安全的。
/usr/local 层级以某种方式复制了根目录,你可以
在 /usr/local/bin 这里找到可执行程序,
在 /usr/local/lib 中找到库,
在 /usr/local/share 中找到架构无关的文件,等等。
使用 /usr/local 树作为你定制安装的软件位置的唯一问题是,你的软件的文件将在这里混杂在一起。
尤其是你安装了多个软件之后,将很难去准确地跟踪 /usr/local/bin 和 /usr/local/lib 中的哪个文件到底属于哪个软件。
它虽然不会导致系统的问题。毕竟,/usr/bin 也是一样混乱的。但是,有一天你想去卸载一个手工安装的软件时它会将成为一个问题。

要解决这个问题,我通常喜欢安装定制的软件到 /opt 子目录下。再次引用 FHS:“/opt 是为安装附加的应用程序软件包而保留的。
因此,我们将在 /opt 下创建一个子目录用于安装。并且,如果有一天我想去卸载它,我只是很简单地去删除那个目录:

https://linux.cn/article-9172-1.html
http://www.pathname.com/fhs/

c. 注意查看作者提供的README, INSTALL等文件

比如gunpg软件的 README 提供的安装步骤。

As with all packages, you just have to do
./configure
make
make check
make install
......
You may run
gpgconf --list-dirs
to view the default directories used by GnuPG.

提供了查看默认安装路径的方法。

比如gunpg软件的 INSTALL 提供的安装步骤。

The simplest way to compile this package is:

1. `cd' to the directory containing the package's source code and type
`./configure' to configure the package for your system.
Running `configure' might take a while. While running, it prints
some messages telling which features it is checking for.
2. Type `make' to compile the package.
3. Optionally, type `make check' to run any self-tests that come with
the package.
4. Type `make install' to install the programs and any data files and
documentation.
5. You can remove the program binaries and object files from the
source code directory by typing `make clean'. To also remove the
files that `configure' created (so you can compile the package for
a different kind of computer), type `make distclean'. There is
also a `make maintainer-clean' target, but that is intended mainly
for the package's developers. If you use it, you may have to get
all sorts of other programs in order to regenerate files that came
with the distribution.
......
By default, `make install' installs the package's commands under
`/usr/local/bin', include files under `/usr/local/include', etc. You
can specify an installation prefix other than `/usr/local' by giving
`configure' the option `--prefix=PREFIX'.

有安装步骤及安装路径的描述等

==========

原文:https://blog.csdn.net/liupeifeng3514/article/details/79054510
./configure:
解压完成就正式开始安装了(补充一点,开始configure之前,如有必要,请使用patch工具为源码打上相应的补丁),
首先跳转到源码的解压目录,众所周知,开始configure前还是应该仔细阅读源码目录下的README或者INSTALL文件,好多安装中的注意事项在这里都有所罗列,
configure实际上是一个脚本文件,在当前目录中键入”./configure”,shell就会运行当前目录下的configure脚本,
有一点必须说明,在整个configure过程,其实编译尚未进行,configure仅仅是做编译相关的准备工作,它主要对您当前的工作平台做一些依赖性检查,
比如编译器是否安装,连接器是否存在,如果在检测的过程没有任何错误,你很幸运,configure脚本会在当前目录下生成下一步编译链接所要用到的另一个文件Makefile,
当然configure支持及其丰富的命令行参数,可以键入”./configre –help”获取具体的信息。
总的来说,此文件有两个功能:1、让用户选定编译特性;2、检查编译环境。configure执行后将生成MakeFile文件。

make
如果configure过程正确完成,那么在源码目录,会生成相应的Makefile文件,Makefile文件简单来说包括的是一组文件依赖关系以及编译链接的相关步骤,
事实上真正的编译链接工作也不是make所做的,make只是一个通用的工具,一般情况下,make会根据Makefile中的规则调用合适的编译器编译所有与当前软件相依赖的源码,
生成所有相关的目标文件,最后再使用链接器生成最终的可执行程序。


3、配置过程
3.1 修改PATH环境变量,以能够识别此程序的二进制文件路径
修改/etc/profile文件,在文件中添加:
export PATH=$PATH:/path/to/somewhere  #记得是可执行文件所在的目录,路径中不要包含可执行文件。
然后执行 :
source /etc/profile #是我们的修改生效    

3.2 增加系统搜索库文件的路径
默认情况下,系统搜索库文件的路径/lib, /usr/lib; 要增添额外搜寻路径(注意:有的程序不提供库文件,那就不需要此设置了)
在/etc/ld.so.conf.d/中创建以.conf为后缀名的文件,而后把要增添的路径直接写至此文件中;然后执行如下命令使其生效:
ldconfig

3.3 增加系统搜索头文件的路径
如果程序提供了库文件,也会相应的提供头文件,一般在安装目录的include目录下,系统默认扫描头文件的路径是:/usr/include。
我们可以在/usr/include下用链接连接到我们安装程序的头文件。
ln -s /usr/local/nginx/include /usr/include/yourname
==================

http://www.jinbuguo.com/linux/understand_package_install.html
深入理解软件包的配置、编译与安装

......

猜你喜欢

转载自www.cnblogs.com/sztom/p/10565648.html