centos7编译安装git出错--openssl

本文介绍了在CentOS上从源码编译安装Git过程中遇到的与OpenSSL相关的错误及解决方法,包括升级OpenSSL版本、调整配置和软链接等步骤。

一、异常信息
安装步骤是这样的:
1、下载git-2.11.0.tar.gz 到 /usr/local/src

[root@tCentos7 ~]# cd /usr/local/src
[root@tCentos7 ~]# wget https://www.kernel.org/pub/software/scm/git/git-2.11.1.tar.gz

2、安装依赖的库

[root@tCentos7 ~]#yum groupinstall "Development Tools"
[root@tCentos7 ~]# yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-CPAN perl-devel perl-ExtUtils-Embed

3、 删除原本的安装的git

[root@tCentos7 ~]# yum remove git -y

4、编译安装

[root@tCentos7 ~]# cd /usr/local/src
[root@tCentos7 ~]# tar -zvxf git-2.11.1.tar.gz
[root@tCentos7 ~]# cd git-2.11.1
[root@tCentos7 ~]# ./configure
[root@tCentos7 ~]# make
[root@tCentos7 ~]# make install

在make这一步出错,错误代码:

imap-send.o: In function `sk_GENERAL_NAME_num':
/usr/local/include/openssl/x509v3.h:165: undefined reference to `OPENSSL_sk_num'
imap-send.o: In function `sk_GENERAL_NAME_value':
/usr/local/include/openssl/x509v3.h:165: undefined reference to `OPENSSL_sk_value'
imap-send.o: In function `sk_GENERAL_NAME_pop_free':
/usr/local/include/openssl/x509v3.h:165: undefined reference to `OPENSSL_sk_pop_free'
/usr/local/include/openssl/x509v3.h:165: undefined reference to `OPENSSL_sk_pop_free'
imap-send.o: In function `ssl_socket_connect':
/usr/local/src/git-2.11.1/imap-send.c:287: undefined reference to `OPENSSL_init_ssl'
/usr/local/src/git-2.11.1/imap-send.c:288: undefined reference to `OPENSSL_init_ssl'
/usr/local/src/git-2.11.1/imap-send.c:290: undefined reference to `TLS_method'
/usr/local/src/git-2.11.1/imap-send.c:303: undefined reference to `SSL_CTX_set_options'
collect2: error: ld returned 1 exit status
make: *** [git-imap-send] Error 1

好像跟OPENSSL有关,我升级了openssl,自带的是OpenSSL 1.0.1e-fips 11 Feb 2013,我把它升级到了openssl-1.1.0d
二、解决步骤
1、在终端使用wget下载最新没有漏洞的版本

wget https://www.openssl.org/source/openssl-1.1.0f.tar.gz

2、执行编译

cd openssl-1.1.0f/
./config  --prefix=/usr/local/related/openssl --openssldir=/usr/local/related/openssl/ssl
make && make install
./config shared --prefix=/usr/local/related/openssl --openssldir=/usr/local/related/openssl/ssl
make clean
make && make install

3、配置
备份原来的openssl命令

mv /usr/bin/openssl /usr/bin/openssl.bak

备份原来的openssl目录 (一些环境下本地include下面没有旧的openssl目录,这里我的环境是liunx7,centos6.8)

mv /usr/include/openssl  /usr/include/openssl.bak

将安装好的openssl 的openssl命令软连到/usr/bin/openssl

ln -s /usr/local/related/openssl/bin/openssl /usr/bin/openssl

将安装好的openssl 的openssl目录软连到/usr/include/openssl

ln -s /usr/local/related/openssl/include/openssl /usr/include/openssl

修改系统自带的openssl库文件,如/usr/local/lib64/libssl.so(根据机器环境而定) 软链到升级后的libssl.so

ln -s /usr/local/related/openssl/lib/libssl.so.1.1 /usr/local/lib64/libssl.so
----注意时usr/local下的lib64不是/usr/lib64,两个目录下又同名目录

在/etc/ld.so.conf文件中写入openssl库文件的搜索路径

echo "/usr/local/related/openssl/lib" >> /etc/ld.so.conf

使修改后的/etc/ld.so.conf生效

ldconfig -v

最好查看下openssl版本号,看是否已经更新成最新的,

openssl version -a

3,

使用

头文件目录:

/usr/local/related/openssl/include  

gcc编译的时候加-lssl,同时指定libssl.so。

其他:
1、openssl官网:https://www.openssl.org/source/

<think>我们正在CentOS 7上从源码安装Git 2.0.0。由于CentOS 7自带的Git版本较旧(1.8.3.1),因此需要从源码安装。以下是详细步骤: ### 1. 安装依赖包 首先,安装编译Git所需的依赖包: ```bash sudo yum groupinstall "Development Tools" -y sudo yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel -y ``` ### 2. 下载Git源码 下载Git 2.0.0的源码包并解压: ```bash wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.0.0.tar.gz tar -xzvf git-2.0.0.tar.gz cd git-2.0.0 ``` ### 3. 编译安装 配置、编译安装: ```bash make configure ./configure --prefix=/usr/local/git # 指定安装目录为/usr/local/git make sudo make install ``` ### 4. 设置环境变量 将Git的可执行文件路径添加到系统环境变量中: ```bash echo 'export PATH=/usr/local/git/bin:$PATH' | sudo tee /etc/profile.d/git.sh source /etc/profile.d/git.sh ``` ### 5. 验证安装 检查Git版本: ```bash git --version ``` 应输出:`git version 2.0.0` ### 6. 配置Git(可选) 设置全局用户名和邮箱: ```bash git config --global user.name "Your Name" git config --global user.email "your@email.com" ``` ### 常见问题解决 - **编译依赖问题**:如果编译失败,检查是否安装了所有依赖包[^1]。 - **旧版本冲突**:如果系统原有Git仍在调用,确保`/usr/local/git/bin`在`PATH`中优先级更高。 > **注意**:Git 2.0.0发布于2014年,部分新功能可能缺失。建议考虑安装较新版本(如2.40+)以获得安全更新和功能改进。 §§相关问题§§ 1. 如何卸载通过源码安装Git? 2. CentOS 7如何通过yum安装最新版Git? 3. Git安装后如何配置SSH密钥认证?</think>### 在 CentOS 7 上从源码安装 Git 2.0.0 完整指南 #### 1. 安装编译依赖 ```bash # 安装基础开发工具链 sudo yum groupinstall "Development Tools" -y # 安装 Git 编译依赖 sudo yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-ExtUtils-MakeMaker -y ``` #### 2. 下载并解压源码 ```bash # 下载 Git 2.0.0 源码 wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.0.0.tar.gz # 解压源码包 tar -xzvf git-2.0.0.tar.gz cd git-2.0.0 ``` #### 3. 配置编译选项 ```bash # 配置安装路径 (默认为 /usr/local) ./configure --prefix=/usr/local # 若需自定义路径 (如 /opt/git) # ./configure --prefix=/opt/git ``` #### 4. 编译安装 ```bash # 编译源码 (使用多核加速) make -j$(nproc) # 安装到系统 sudo make install ``` #### 5. 配置环境变量 ```bash # 添加 PATH 变量 echo 'export PATH=/usr/local/bin:$PATH' | sudo tee /etc/profile.d/git.sh # 立即生效 source /etc/profile.d/git.sh ``` #### 6. 验证安装 ```bash # 检查版本 git --version # 应输出: git version 2.0.0 # 测试基本功能 git init test-repo && cd test-repo echo "Hello Git 2.0" > test.txt git add . && git commit -m "Initial commit" ``` #### 常见问题解决 1. **依赖缺失错误** 若出现 `make: *** No targets specified and no makefile found`: ```bash # 重新安装开发工具链 sudo yum reinstall gcc make autoconf automake -y ``` 2. **旧版本冲突** 若系统预装 Git 干扰: ```bash # 移除旧版本 (谨慎操作) sudo yum remove git -y # 重新安装依赖后再次编译 ``` 3. **权限问题** 安装添加 `sudo`,确保目标目录可写: ```bash sudo chown -R $(whoami) /usr/local # 仅限测试环境 ``` #### 卸载方法 ```bash # 进入源码目录 cd git-2.0.0 # 执行卸载 sudo make uninstall # 清理残留文件 sudo rm /usr/local/bin/git* sudo rm -rf /usr/local/libexec/git-core ``` > **注意**:Git 2.0.0 发布于 2014 年,建议考虑安装更新版本(如 2.40+)以获得安全更新和新特性。可通过 `git clone https://github.com/git/git` 获取最新源码[^2]。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值