如何在 Ubuntu 上安裝最新版本的 Git

如何在 Ubuntu 上安裝最新版本的 Git

一種方法是從源代碼安裝。這種很酷又老派的方法不適合所有人。值得慶幸的是,Ubuntu Git 維護團隊提供了 PPA,莫可以使用它輕鬆地安裝最新的穩定 Git 版本。-- Abhishek Prakash(作者)

在 Ubuntu 上安裝 Git 非常容易。它存在於 Ubuntu 的主倉庫 中,你可以像這樣 使用 apt 命令 安裝它:

<code>sudo apt install git/<code>

很簡單?是不是?

只有一點點小問題(這可能根本不是問題),就是它安裝的 Git 版本。

在 LTS 系統上,軟件穩定性至關重要,這就是為什麼 Ubuntu 18.04 和其他發行版經常提供較舊但穩定的軟件版本的原因,它們都經過發行版的良好測試。

這就是為什麼當你檢查 Git 版本時,會看到安裝的版本會比 Git 網站上當前最新 Git 版本 舊:

<code>$ git --versiongit version 2.17.1/<code>

在編寫本教程時,網站上提供的版本為 2.25。那麼,如何在 Ubuntu 上安裝最新的 Git?

在基於 Ubuntu 的 Linux 發行版上安裝最新的 Git

一種方法是 從源代碼安裝 。這種很酷又老派的方法不適合所有人。值得慶幸的是,Ubuntu Git 維護團隊提供了 PPA ,莫可以使用它輕鬆地安裝最新的穩定 Git 版本。

<code>sudo add-apt-repository ppa:git-core/ppasudo apt updatesudo apt install git/<code>

即使你以前使用 apt 安裝了 Git,它也將更新為最新的穩定版本。

<code>$ git --versiongit version 2.25.0/<code>

使用PPA 的好處在於,如果發佈了新的 Git 穩定版本,那麼就可以通過系統更新獲得它。 僅更新 Ubuntu 來獲取最新的 Git 穩定版本。

配置 Git (推薦給開發者)

如果你出於開發目的安裝了 Git,你會很快開始克隆倉庫,進行更改並提交更改。

如果你嘗試提交代碼,那麼你可能會看到 “Please tell me who you are” 這樣的錯誤:

<code>$ git commit -m "update readme"*** Please tell me who you are.Run  git config --global user.email "[email protected]"  git config --global user.name "Your Name"to set your account's default identity.Omit --global to set the identity only in this repository.fatal: unable to auto-detect email address (got 'abhishek@itsfoss.(none)')/<code>

這是因為你還沒配置必要的個人信息。

正如錯誤已經暗示的那樣,你可以像這樣設置全局 Git 配置:

<code>git config --global user.name "Your Name"git config --global user.email "[email protected]"/<code>

你可以使用以下命令檢查 Git 配置:

<code>git config --list/<code>

它應該顯示如下輸出:

<code>[email protected]=Your Name/<code>

配置保存在 ~/.gitconfig 中。你可以手動修改配置。

結尾

我希望這個小教程可以幫助你在 Ubuntu 上安裝 Git。使用 PPA,你可以輕鬆獲得最新的 Git 版本。

如果你有任何疑問或建議,請隨時在評論部分提問。也歡迎直接寫“謝謝” :)


via: itsfoss.com

作者: Abhishek Prakash 選題: lujun9972 譯者: geekpi 校對: wxy

本文由 LCTT 原創編譯, Linux中國 榮譽推出


分享到:


相關文章: