centos7从源码安装git-2.0.0.tar.gz
时间: 2025-07-30 08:14:49 浏览: 6
<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 "[email protected]"
```
### 常见问题解决
- **编译依赖问题**:如果编译失败,检查是否安装了所有依赖包[^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]。
阅读全文
相关推荐




















