Linux使用源码安装软件示例

97 篇文章 7 订阅

Linux使用源码安装软件示例

在Linux下安装一个软件可以使用rpm/yum安装也可以使用源码安装。

源码解压缩后放置在哪里?

生成的可执行文件放置在哪里?

……

下面看一个简单的使用源码安装软件的例子:

(注:这个例子来自于《鸟哥的Linux私房菜》,下面是我实践的过程)

Tarball:ntp-4.2.8p10.tar.gz

1.将Tarball放置在/root目录下:

[root@localhost ~]# ll
total 6928
-rw-------. 1 root root    2692 Apr 13  2017 anaconda-ks.cfg
……
-rw-r--r--. 1 root root 6998648 Apr 12 17:08 ntp-4.2.8p10.tar.gz
……

2.将Tarball解压缩在/usr/local/src下:

[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# tar zxvf /root/ntp-4.2.8p10.tar.gz 
ntp-4.2.8p10/
ntp-4.2.8p10/packageinfo.sh
ntp-4.2.8p10/README.pullrequests
ntp-4.2.8p10/configure
……

注意Tarball中包含的configure,其可以检测运行环境,生成makefile。

[root@localhost src]# ll
total 4
drwxrwsr-x. 23 427 6011 4096 Mar 21 07:47 ntp-4.2.8p10
[root@localhost src]# cd ntp-4.2.8p10/
[root@localhost ntp-4.2.8p10]# ll
total 7044
-rw-rw-r--.  1 427 6011   50020 Mar 21 07:37 aclocal.m4
drwxrwsr-x.  2 427 6011    4096 Mar 21 07:47 adjtimed
-rw-rw-r--.  1 427 6011     605 Jun 22  2011 bincheck.mf
-rwxrwxr-x.  1 427 6011    4801 Jun 17  2015 bootstrap
-rwxrwxr-x.  1 427 6011    4239 Dec 23  2014 build
-rw-rw-r--.  1 427 6011  242006 Mar 21 06:34 ChangeLog
-rw-rw-rw-.  1 427 6011     374 Jan  8  2012 check-libopts.mf
drwxrwsr-x.  2 427 6011    4096 Mar 21 07:47 clockstuff
-rw-rw-r--.  1 427 6011 5225786 Feb  1 04:41 CommitLog
-rw-rw-r--.  1 427 6011  195223 Jan  4  2007 CommitLog-4.1.0
drwxrwsr-x.  2 427 6011    4096 Jan 31 23:19 conf
-rw-rw-r--.  1 427 6011   42801 Mar 21 07:41 config.h.in
-rwxrwxr-x.  1 427 6011  937829 Mar 21 07:37 configure
……

3.使用configure检查环境并生成makefile:

[root@localhost ntp-4.2.8p10]# ./configure --prefix=/usr/local/ntp
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether make supports nested variables... (cached) yes
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking for style of include used by make... GNU
checking for cc... cc
……
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
……
configure: creating ./config.status
config.status: creating Makefile
config.status: creating adjtimed/Makefile
……

使用configure会检查编译器、链接器、头文件等等,最终生成makefile文件。

4.可以先make clean下(不是必要步骤,但是可以执行下,安全点):

[root@localhost ntp-4.2.8p10]# make clean
Making clean in sntp
make[1]: Entering directory `/usr/local/src/ntp-4.2.8p10/sntp'
Making clean in include
make[2]: Entering directory `/usr/local/src/ntp-4.2.8p10/sntp/include'
rm -rf .libs _libs
……

5.执行make进行源码编译:

[root@localhost ntp-4.2.8p10]# make
Compiling with GCC now generates lots of new warnings.

Don't be concerned. They're just warnings.

Don't send bug reports about the warnings, either.

Feel free to send patches that fix these warnings, though.

cd ./html && \
    ../scripts/build/checkHtmlFileDates
cd . && \
    ./scripts/build/checkChangeLog
make  all-recursive
make[1]: Entering directory `/usr/local/src/ntp-4.2.8p10'
Making all in sntp
……

6.make install安装到指定目录:

[root@localhost ntp-4.2.8p10]# make install
cd ./html && \
    ../scripts/build/checkHtmlFileDates
cd . && \
    ./scripts/build/checkChangeLog
make  install-recursive
make[1]: Entering directory `/usr/local/src/ntp-4.2.8p10'
Making install in sntp
make[2]: Entering directory `/usr/local/src/ntp-4.2.8p10/sntp'
[ ! -r ./../COPYRIGHT ]                 \
    || [ check-COPYRIGHT-submake -nt ./../COPYRIGHT ]   \
    || make  check-COPYRIGHT-submake
make  install-recursive
make[3]: Entering directory `/usr/local/src/ntp-4.2.8p10/sntp'
Making ins
[root@localhost ntp-4.2.8p10]# cd /usr/local
[root@localhost local]# ll
total 40
drwxr-xr-x. 2 root root 4096 Sep 23  2011 bin
drwxr-xr-x. 2 root root 4096 Sep 23  2011 etc
drwxr-xr-x. 2 root root 4096 Sep 23  2011 games
drwxr-xr-x. 2 root root 4096 Sep 23  2011 include
drwxr-xr-x. 2 root root 4096 Sep 23  2011 lib
drwxr-xr-x. 2 root root 4096 Sep 23  2011 libexec
drwxr-xr-x. 6 root root 4096 Apr 12 17:14 ntp
drwxr-xr-x. 2 root root 4096 Sep 23  2011 sbin
drwxr-xr-x. 5 root root 4096 Apr 13  2017 share
drwxr-xr-x. 3 root root 4096 Apr 12 17:09 src
[root@localhost local]# cd ntp
[root@localhost ntp]# ll
total 16
drwxr-xr-x. 2 root root 4096 Apr 12 17:14 bin
drwxr-xr-x. 2 root root 4096 Apr 12 17:14 libexec
drwxr-xr-x. 2 root root 4096 Apr 12 17:14 sbin
drwxr-xr-x. 5 root root 4096 Apr 12 17:14 share
[root@localhost ntp]# ll bin
total 6008
-rwxr-xr-x. 1 root root    2844 Apr 12 17:14 calc_tickadj
-rwxr-xr-x. 1 root root 2255174 Apr 12 17:14 ntpd
-rwxr-xr-x. 1 root root  384466 Apr 12 17:14 ntpdate
-rwxr-xr-x. 1 root root  791615 Apr 12 17:14 ntpdc
-rwxr-xr-x. 1 root root  666160 Apr 12 17:14 ntp-keygen
-rwxr-xr-x. 1 root root  832389 Apr 12 17:14 ntpq
-rwxr-xr-x. 1 root root  198198 Apr 12 17:14 ntptime
-rwxr-xr-x. 1 root root    3570 Apr 12 17:14 ntptrace
-rwxr-xr-x. 1 root root    3210 Apr 12 17:14 ntp-wait
-rwxr-xr-x. 1 root root  972854 Apr 12 17:14 sntp
-rwxr-xr-x. 1 root root   11333 Apr 12 17:14 tickadj
-rwxr-xr-x. 1 root root   11635 Apr 12 17:14 update-leap
[root@localhost ntp]# ll share/
doc/ man/ ntp/ 
[root@localhost ntp]# ll share/
total 12
drwxr-xr-x. 4 root root 4096 Apr 12 17:14 doc
drwxr-xr-x. 5 root root 4096 Apr 12 17:14 man
drwxr-xr-x. 3 root root 4096 Apr 12 17:14 ntp
[root@localhost ntp]# cd

上述执行时的输出贴了一堆,总结起来就是:

1.将源码解压在/usr/local/src目录下;

2.进入对应的目录,执行configure,注意prefix指定makefile中最后安装的目录,这个最后安装的目录通常是/usr/local/xxx,xxx是软件名;

3.执行make clean来先清除下“可能存在的.o文件”,实际上这一步一般不用也可以;

4.执行make编译源代码(注意,是编译,不是安装);

5.执行make install安装。

如果仅仅是安装到此为止就可以了,了解更多可以往下看看。

所谓的Tarball文件实际上是将源码先用tar打包,然后使用gzip或者bzip2压缩后得到的文件。

通常使用gzip压缩后得到的Tarball文件是:

xxx.tar.gz
xxx.tgz

通常使用bzip2压缩后得到的Tarball文件是:

xxx.tar.bz2

解压缩一个Tarball文件通常包含以下几项:

1.源代码文件;

2.configure/config检测程序;

3.自述文件README和安装说明INSTALL;

使用configure/config生成makefile然后即可安装。

注意:

make使用的是makefile或者Makefile,configure/config也是需要autoconfig这个软件来辅助的。

原本的Linux distribution发布安装的软件是在/usr中的,用户自行安装的软件建议放置在/usr/local下。

对于configure/config,如果没有显式地指明–prefix=/usr/local/xxx,那么默认将会是/usr/local。

对了,最后别忘记在/etc/man.config中加上刚装的软件的man路径。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Linux 上,你可以使用包管理器来快速安装软件。不同的 Linux 发行版可能使用不同的包管理器,下面是一些常见的包管理器及其使用方法: 1. apt (Advanced Packaging Tool):适用于 Debian、Ubuntu 和基于它们的发行版。 - 安装软件:`sudo apt install 软件名称` - 示例:`sudo apt install firefox` 2. yum:适用于 CentOS、Fedora 和基于它们的发行版。 - 安装软件:`sudo yum install 软件名称` - 示例:`sudo yum install nginx` 3. dnf (Dandified Yum):Fedora 22+ 版本引入的新一代包管理器。 - 安装软件:`sudo dnf install 软件名称` - 示例:`sudo dnf install git` 4. pacman:适用于 Arch Linux 和基于它的发行版。 - 安装软件:`sudo pacman -S 软件名称` - 示例:`sudo pacman -S neovim` 5. zypper:适用于 openSUSE 和 SUSE Linux Enterprise 等发行版。 - 安装软件:`sudo zypper install 软件名称` - 示例:`sudo zypper install chromium` 以上命令中的 "软件名称" 是你要安装软件包的名字。根据你的 Linux 发行版和包管理器,可能需要使用不同的命令。另外,你可能需要使用管理员权限(使用 `sudo`)来执行这些命令。 除了包管理器之外,还可以通过源码编译和安装软件。这种方式可能需要更多的手动配置和依赖项安装。 请注意,在使用包管理器安装软件之前,建议先更新包管理器的软件包列表,使用以下命令之一: - `sudo apt update` - `sudo yum update` - `sudo dnf update` - `sudo pacman -Syu` - `sudo zypper refresh` 这样可以确保你安装软件是最新的版本。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值