Linux 使用非 root 用户帐户安装 Git

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4039416/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 23:49:12  来源:igfitidea点击:

Installing Git with non-root user account

linuxgitubuntu

提问by BoppreH

I've already set up a Git repository on GitHub and committed a few changes from my Windows machine.

我已经在 GitHub 上设置了一个 Git 存储库,并在我的 Windows 机器上提交了一些更改。

But tomorrow I'll have to work in this repository from a machine running Ubuntu with limited privilege (i.e. no sudo).

但是明天我将不得不从一台运行 Ubuntu 且权限有限(即没有 sudo)的机器上在这个存储库中工作。

Is there a portable version of Git for Linux? Or some source that allows me to compile and install Git only for the current user?

是否有适用于 Linux 的可移植 Git 版本?或者某些允许我仅为当前用户编译和安装 Git 的源代码?

采纳答案by Scott

You can download the git source and do ./configure --prefix=/home/user/myroot && make && make installto install git to your home directory provided you have the build tools. If you don't have the build-essential package installed (dpkg --list|grep build-essential), you will need to install those to your home directory as well.

如果./configure --prefix=/home/user/myroot && make && make install您有构建工具,您可以下载 git 源代码并安装 git 到您的主目录。如果您没有安装 build-essential 包 ( dpkg --list|grep build-essential),您还需要将它们安装到您的主目录中。

回答by demongolem

I don't like link-only answers, but thislink I followed step-by-step on a Fedora machine and it worked without modification. Very, very easy. The binaries end up in your ~/bin directory. You download a tarball, extract the sources, run makeand run make installand that is it.

我不喜欢仅链接的答案,但是我在 Fedora 机器上一步一步地遵循了这个链接,它无需修改就可以工作。非常非常容易。二进制文件最终位于您的 ~/bin 目录中。您下载一个 tarball,提取源代码,运行make并运行make install,就是这样。

As the author states, the 2 prerequisites are gcc and ssh and if you meet these git should work for you as a non-root user.

正如作者所说,两个先决条件是 gcc 和 ssh,如果你满足这些条件,作为非 root 用户,git 应该适合你。

回答by lib

A related answer is https://askubuntu.com/a/350.

一个相关的答案是https://askubuntu.com/a/350

I could get it work with the third method proposed:

我可以使用建议的第三种方法使其工作:

apt-get source git
cd git_vXXX
./configure --prefix=$HOME
make
make install

I don't know why, but when I had tried to install from the source download from github instead, I had a lot of problems with missing dependencies

我不知道为什么,但是当我尝试从 github 上的源下载安装时,我遇到了很多缺少依赖项的问题

回答by 79E09796

To install git and dependencies from source the following maybe useful.

要从源安装 git 和依赖项,以下内容可能有用。

Replace with the location you are installing your non-root apps and consider checking for latest versions of source code.

替换为您安装非 root 应用程序的位置,并考虑检查源代码的最新版本。

wget https://curl.haxx.se/download/curl-7.47.1.tar.gz
tar -xf curl-7.47.1.tar.gz
mkdir <local_curl_dir>
cd curl-7.47.1
./configure --prefix=<local_curl_dir>
make
make install

wget http://downloads.sourceforge.net/expat/expat-2.1.0.tar.gz
tar -xf expat-2.1.0.tar.gz
mkdir <local_expat_dir>
cd expat-2.1.0
./configure --prefix=<local_expat_dir>
make
make install

wget https://github.com/git/git/archive/v2.6.4.tar.gz
tar -xf v2.6.4
mkdir <local_git_dir>
cd git-2.6.4
make configure
./configure --prefix=<local_git_dir>/git --with-curl=<local_curl_dir>/curl --with-expat=<local_expat_dir>/expat
make
make install

回答by bdombro

This is what I ended up doing, the main trick being the make flags:

这就是我最终要做的,主要技巧是 make 标志:

wget -O git.tar.gz https://github.com/git/git/archive/v2.17.0.tar.gz
tar zxf git.tar.gz
mv git-2.17.0 git
cd git
make configure
./configure --prefix=`pwd` --with-curl --with-expat
# ./configure --prefix=`pwd`
# Make flags from https://public-inbox.org/git/CAP8UFD2gKTourXUdB_9_FZ3AEECTDc1Fx1NFKzeaTZDWHC3jxA@mail.gmail.com/
make NO_GETTEXT=Nope NO_TCLTK=Nope
make install NO_GETTEXT=Nope NO_TCLTK=Nope

Credits:

学分:

  1. 79E09796's answer above was a good tip, but didn't work for my case on Cloudways and did not require compiling curl and expat.

  2. A random email record I found on the internet: https://public-inbox.org/git/CAP8UFD2gKTourXUdB_9_FZ3AEECTDc1Fx1NFKzeaTZDWHC3jxA@mail.gmail.com/

  1. 上面 79E09796 的回答是一个很好的提示,但不适用于我在 Cloudways 上的情况,并且不需要编译 curl 和 expat。

  2. 我在互联网上发现的随机电子邮件记录:https: //public-inbox.org/git/CAP8UFD2gKTourXUdB_9_FZ3AEECTDc1Fx1NFKzeaTZDWHC3jxA@mail.gmail.com/

回答by Reagen

for the latest version(which i mean git-2.25.0-rc1 or upper), you need to

对于最新版本(我的意思是 git-2.25.0-rc1 或更高版本),您需要

wget https://github.com/git/git/releases/tag/v2.25.0-rc1 -O git.zip 
unzip git.zip 
cd git-2.25.0-rc1 
export PATH=`pwd`:$PATH

and of course, you can add the last line into your .bashrc or .zshrc or something else for more convenience.

当然,为了更方便,您可以将最后一行添加到 .bashrc 或 .zshrc 或其他内容中。