---
# System prepended metadata

title: 在 Ubuntu 環境中安裝與設定 Git
tags: [Ubuntu, Git, Linux, git]

---

# 在 Ubuntu 環境中安裝與設定 Git

[![hackmd-github-sync-badge](https://hackmd.io/2gpd8KYNS5Ku-G4UYTea-Q/badge)](https://hackmd.io/@stevechang/How_to_Install_and_Configure_Git_on_Ubuntu)

這篇文章將說明如何在 Ubuntu 24.04.3 LTS 環境中完成 Git 的基礎建置。

## 1. 確認 Ubuntu 版本

在開始之前，我們可以先確認目前的 Ubuntu 的版本是否符合需求，以確保環境的一致性。

[如何查看目前運行中的 Ubuntu 版本？](https://hackmd.io/@stevechang/How_to_Check_Your_Current_Ubuntu_Version)

## 2. 更新系統軟體

為了確保我們下載的是最新且穩定的版本，我們先透過 Package Manager (套件管理器) 更新系統的索引與現有套件：

```shell
sudo apt update && sudo apt upgrade -y
```

## 3. 安裝 Git

接著，我們直接安裝 Git 主程式：

```shell
sudo apt install git -y
```

安裝完後，可以輸入 `git --version` 來確認版本資訊。

## 4. 設定使用者資訊

Git 會在每一次的 Commit 中記錄作者資訊。我們需要設定 Global Configuration 來定義身分。

### 設定使用者顯示名稱

輸入下列指令，將 `<your_name>` 換成你想要顯示名稱。

```shell
git config --global user.name "<your_name>"
```

### 設定電子郵件

輸入下列指令，將 `<your_email@example.com>` 換成你的聯絡信箱。

```shell
git config --global user.email "<your_email@example.com>"
```

## 5. 設定預設的文字編輯器

當我們需要撰寫 Commit Message 時，Git 會呼叫預設的編輯器。Ubuntu 通常內建 Nano，但我們可以根據需求換成 Vim。

### 安裝 Vim

```shell
sudo apt install vim -y
```

### 將 Vim 設為 Git 預設編輯器

```shell
git config --global core.editor "vim"
```

## References

- Git 官方文件
[https://git-scm.com/docs](https://git-scm.com/docs)
- git config 使用說明
[https://git-scm.com/docs/git-config](https://git-scm.com/docs/git-config)

###### tags: `Git` `git` `Ubuntu` `Linux`
