如何在Ubuntu上安裝最新版本的Git
在 Ubuntu 上安裝 Git 非常容易。它存在于 Ubuntu 的主倉庫中,你可以像這樣使用 apt 命令安裝它:
sudo apt install git
很簡單?是不是?
只有一點點小問題(這可能根本不是問題),就是它安裝的 Git 版本。
在 LTS 系統上,軟件穩定性至關重要,這就是為什么 Ubuntu 18.04 和其他發行版經常提供較舊但穩定的軟件版本的原因,它們都經過發行版的良好測試。
這就是為什么當你檢查 Git 版本時,會看到安裝的版本會比 Git 網站上當前最新 Git 版本舊:
$ git --versiongit version 2.17.1
在編寫本教程時,網站上提供的版本為 2.25。那么,如何在 Ubuntu 上安裝最新的 Git?
在基于 Ubuntu 的 Linux 發行版上安裝最新的 Git
一種方法是從源代碼安裝。這種很酷又老派的方法不適合所有人。值得慶幸的是,Ubuntu Git 維護團隊提供了 PPA,莫可以使用它輕松地安裝最新的穩定 Git 版本。
sudo add-apt-repository ppa:git-core/ppasudo apt updatesudo apt install git
即使你以前使用 apt 安裝了 Git,它也將更新為最新的穩定版本。
$ git --versiongit version 2.25.0
使用PPA 的好處在于,如果發布了新的 Git 穩定版本,那么就可以通過系統更新獲得它。僅更新 Ubuntu 來獲取最新的 Git 穩定版本。
配置 Git (推薦給開發者)
如果你出于開發目的安裝了 Git,你會很快開始克隆倉庫,進行更改并提交更改。
如果你嘗試提交代碼,那么你可能會看到 “Please tell me who you are” 這樣的錯誤:
$ git commit -m "update readme"*** Please tell me who you are.Rungit config --global user.email "you@example.com"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)')
這是因為你還沒配置必要的個人信息。
正如錯誤已經暗示的那樣,你可以像這樣設置全局 Git 配置:
git config --global user.name "Your Name"git config --global user.email "you@example.com"
你可以使用以下命令檢查 Git 配置:
git config --list
它應該顯示如下輸出:
user.email=you@example.comuser.name=Your Name
配置保存在 ~/.gitconfig 中。你可以手動修改配置。
結尾
我希望這個小教程可以幫助你在 Ubuntu 上安裝 Git。使用 PPA,你可以輕松獲得最新的 Git 版本。




















