Ubuntu16.04 Install Git


## 安装Git ubuntu系统安装软件一般直接apt-get install就OK了,所以可以直接用: - johnathon@ubuntu16:~$ sudo apt-get install git 查看版本: - johnathon@ubuntu16:~$ git --version git version 2.7.4

当前最新版本并不是2.7.4,而是2.13.3,所以直接这样安装的话并不能安装最新的git版本,正确的步骤按照以下进行

  1. sudo add-apt-repository ppa:git-core/ppa

     johnathon@ubuntu16ohnathon@ubuntu16:~$ sudo add-apt-repository ppa:git-core/ppa
      The most current stable version of Git for Ubuntu.
    
     For release candidates, go to https://launchpad.net/~git-core/+archive/candidate .
      More info: https://launchpad.net/~git-core/+archive/ubuntu/ppa
     Press [ENTER] to continue or ctrl-c to cancel adding it
    
     gpg: keyring `/tmp/tmpbb9o0lni/secring.gpg' created
     gpg: keyring `/tmp/tmpbb9o0lni/pubring.gpg' created
     gpg: requesting key E1DF1F24 from hkp server keyserver.ubuntu.com
     gpg: /tmp/tmpbb9o0lni/trustdb.gpg: trustdb created
     gpg: key E1DF1F24: public key "Launchpad PPA for Ubuntu Git Maintainers" imported
     gpg: Total number processed: 1
     gpg:               imported: 1  (RSA: 1)
     OK
    
  2. 更新软件源,sudo apt-get update

     johnathon@ubuntu16:~$ sudo apt-get update
     Hit:1 http://cn.archive.ubuntu.com/ubuntu xenial InRelease
     Hit:2 http://cn.archive.ubuntu.com/ubuntu xenial-updates InRelease
     Hit:3 http://cn.archive.ubuntu.com/ubuntu xenial-backports InRelease
     Get:4 http://ppa.launchpad.net/git-core/ppa/ubuntu xenial InRelease [17.5 kB]
     Hit:5 http://security.ubuntu.com/ubuntu xenial-security InRelease
     Get:6 http://ppa.launchpad.net/git-core/ppa/ubuntu xenial/main amd64 Packages [3256 B]
     Get:7 http://ppa.launchpad.net/git-core/ppa/ubuntu xenial/main i386 Packages [3248 B]
     Get:8 http://ppa.launchpad.net/git-core/ppa/ubuntu xenial/main Translation-en [2496 B]
     Fetched 26.5 kB in 1s (13.7 kB/s)
     Reading package lists... Done
    
  3. 安装git,sudo apt-get install git

     johnathon@ubuntu16:~$ sudo apt-get install git
     Reading package lists... Done
     Building dependency tree
     Reading state information... Done
     The following packages were automatically installed and are no longer required:
       linux-headers-4.8.0-36 linux-headers-4.8.0-36-generic
       linux-image-4.8.0-36-generic linux-image-extra-4.8.0-36-generic
     Use 'sudo apt autoremove' to remove them.
     The following additional packages will be installed:
       git-man
     Suggested packages:
       git-daemon-run | git-daemon-sysvinit git-doc git-el git-email git-gui gitk
       gitweb git-arch git-cvs git-mediawiki git-svn
     The following NEW packages will be installed:
       git
     The following packages will be upgraded:
       git-man
     1 upgraded, 1 newly installed, 0 to remove and 129 not upgraded.
     Need to get 6174 kB of archives.
     After this operation, 30.4 MB of additional disk space will be used.
     Do you want to continue? [Y/n] y
     Get:1 http://ppa.launchpad.net/git-core/ppa/ubuntu xenial/main amd64 git-man all 1:2.13.0-0ppa1~ubuntu16.04.1 [1448 kB]
     Get:2 http://ppa.launchpad.net/git-core/ppa/ubuntu xenial/main amd64 git amd64 1:2.13.0-0ppa1~ubuntu16.04.1 [4726 kB]
     Fetched 6174 kB in 19s (322 kB/s)
     perl: warning: Setting locale failed.
     perl: warning: Please check that your locale settings:
         LANGUAGE = (unset),
         LC_ALL = (unset),
         LC_TIME = "zh_CN.UTF-8",
         LC_MONETARY = "zh_CN.UTF-8",
         LC_CTYPE = "UTF-8",
         LC_ADDRESS = "zh_CN.UTF-8",
         LC_TELEPHONE = "zh_CN.UTF-8",
         LC_NAME = "zh_CN.UTF-8",
         LC_MEASUREMENT = "zh_CN.UTF-8",
         LC_IDENTIFICATION = "zh_CN.UTF-8",
         LC_NUMERIC = "zh_CN.UTF-8",
         LC_PAPER = "zh_CN.UTF-8",
         LANG = "en_US.UTF-8"
         are supported and installed on your system.
     perl: warning: Falling back to a fallback locale ("en_US.UTF-8").
     locale: Cannot set LC_CTYPE to default locale: No such file or directory
     locale: Cannot set LC_ALL to default locale: No such file or directory
     (Reading database ... 247161 files and directories currently installed.)
     Preparing to unpack .../git-man_1%3a2.13.0-0ppa1~ubuntu16.04.1_all.deb ...
     Unpacking git-man (1:2.13.0-0ppa1~ubuntu16.04.1) over (1:2.7.4-0ubuntu1.1) ...
     Selecting previously unselected package git.
     Preparing to unpack .../git_1%3a2.13.0-0ppa1~ubuntu16.04.1_amd64.deb ...
     Unpacking git (1:2.13.0-0ppa1~ubuntu16.04.1) ...
     Processing triggers for man-db (2.7.5-1) ...
     Setting up git-man (1:2.13.0-0ppa1~ubuntu16.04.1) ...
     Setting up git (1:2.13.0-0ppa1~ubuntu16.04.1) ...
    
  4. 查看git版本

     johnathon@ubuntu16:~$ git --version
     git version 2.13.0
    

配置Git

  • 设置用户名和邮箱
      johnathon@ubuntu16:~$ git config --global user.name '*'
      johnathon@ubuntu16:~$ git config --global user.email '*@*.com'
    
  • home目录下会生成.gitconfig文件,其内容正是上面步骤配置的信息
      johnathon@ubuntu16:~$ ll .gitconfig
      -rw-rw-r-- 1 johnathon johnathon 58 Jul 22 17:17 .gitconfig
    

添加SSH keys到github

  • 运行下面命令,会在.ssh目录下生成相应文件
      johnathon@ubuntu16:~$ ssh-keygen -t rsa -C 'youremail'
    
  • 查看生成的私钥/公钥
      johnathon@ubuntu16:~/.ssh$ ll
      total 20
      drwx------  2 johnathon johnathon 4096 Jul 22 17:25 ./
      drwxr-xr-x 22 johnathon johnathon 4096 Jul 22 17:18 ../
      -rw-------  1 johnathon johnathon 1675 Jul 22 17:25 id_rsa
      -rw-r--r--  1 johnathon johnathon  404 Jul 22 17:25 id_rsa.pub
      -rw-r--r--  1 johnathon johnathon  222 Jul  1 21:41 known_hosts
    
  • 将id_rsa.pub中内容拷贝到github中,如下图

文章作者: keepwonder
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 keepwonder !
  目录