Git - 如何验证 Ubuntu 上是否安装了 Git 以及安装位置

问题描述 投票:0回答:7

我是 Ubuntu 和 Git 的新手。如何验证我的机器上是否安装了 git?当我尝试 apt-get 时,我得到:

root@ubuntu:/home/nebojsa# apt-get install git
Reading package lists... Done
Building dependency tree       
Reading state information... Done
git is already the newest version.
The following packages were automatically installed and are no longer required:
  linux-headers-3.13.0-24 linux-headers-3.13.0-24-generic
  linux-headers-3.13.0-39 linux-headers-3.13.0-39-generic
  linux-headers-3.13.0-40 linux-headers-3.13.0-40-generic
  linux-headers-3.13.0-43 linux-headers-3.13.0-43-generic
  linux-image-3.13.0-24-generic linux-image-3.13.0-39-generic
  linux-image-3.13.0-40-generic linux-image-3.13.0-43-generic
  linux-image-extra-3.13.0-24-generic linux-image-extra-3.13.0-39-generic
  linux-image-extra-3.13.0-40-generic linux-image-extra-3.13.0-43-generic
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 133 not upgraded.

但我不知道软件包安装在哪里。

感谢您的帮助!

git ubuntu
7个回答
70
投票

输入

which git
。 它应该返回可执行文件的路径

如果您想查看更多详细信息:https://serverfault.com/questions/96964/list-of-files-installed-from-apt-package


25
投票

只需拨打

git --version
即可。它应该返回类似这样的内容:

$ git --version
git version 1.9.3 (Apple Git-50)

7
投票

像大多数可执行文件一样,

git
安装在
/usr/bin/git
中。

要查看

git
包中的所有文件所在的位置,您可以键入:

dpkg -L git

您需要通过

less
或您最喜欢的页面传输输出;我的系统上有 591 664 行输出。

(并非所有系统都使用与 Ubuntu 相同的包管理器。您可能需要使用

dpkg
以外的其他命令,也许是
rpm
yum
dnf
。)

如果您从源代码而不是通过包管理器安装了 git,则

git
可执行文件可能位于任何位置,具体取决于您的安装方式。如果它在您的
$PATH
中,请输入

type git

type -a git

会告诉你它在哪里。 (假设您使用默认的 bash shell。)


4
投票

which git
是要使用的命令,如果已经安装了git,这会给出安装git的位置,通常是
/usr/bin/git
。如果没有安装git,你将不会得到任何东西。when git is already installed


1
投票

它告诉你

git is already the newest version.

所以一切都应该没问题。

提示:要查看包安装的文件,请运行

dpkg -L git

它会列出很多文件,但最重要的是

/usr/bin/git
。另一个命令
which git
会返回当您运行
git
时正在运行的文件 - 它应该是相同的。


0
投票

是的,git 已经安装了。至于您关于包裹位置的问题,这很可能与您无关。如果您发现自己浏览 Linux 文件系统只是为了执行系统范围内安装的程序,那么有些事情就不对劲了。您通常根本不需要这样做。

对于 git,打开终端并输入“git”将为您提供基础知识。可以输入“man git”来阅读更多内容(man 命令非常适合查找软件包的附加信息)。

如果您想要 git 的图形前端,请参阅此 https://askubuntu.com/questions/227554/what-are-some-gui-clients-for-git


0
投票

你可以试试这个

git --exec-path
© www.soinside.com 2019 - 2024. All rights reserved.