unable to install git from source code - linux

I am new to using git. So i first install git from terminal using apt-get but then i remove it as in ubuntu the version is very old.
After this i install git from source code which i download from https://code.google.com/p/git-core/downloads/list. Then these are the commands used by me
sudo apt-get install libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev build-essential
tar -zxf git-1.9.0.tar.gz
cd git-1.9.0/
make prefix=/usr/local all
sudo make prefix=/usr/local install
Then when i put these commands it is behaving in this manner.
~/git-1.9.0$ which git
/usr/local/bin/git
~/git-1.9.0$ git --version
bash: /usr/bin/git: No such file or directory

Your shell remembers where it found the executable file for commands you run, to save itself the trouble (and you the delays) of hunting them down repeatedly. which isn't a bash builtin, so it doesn't know about that. When you've installed new code it's rarely a bad idea to
$ hash -r # reset the command-lookup hashtable
or if you've got just one particular command in mind,
$ hash -dcommand# forget wherecommandcame from

You might need to add /usr/local/bin/ to your $PATH, perhaps in ~/.bashrc; you might want to put it before /usr/bin/ there.
And you could simply type the entire path of the binary, e.g.
/usr/local/bin/git --version
or
/usr/local/bin/git status
You might try to use strace to understand what is going on.
Did you read git INSTALL file? You probably want to go the autoconf way (e.g. make configure first, then configure with appropriate arguments....) and you surely need to give relevant arguments at configure time, in particular --exec-prefix= and/or --libexecdir= ....

Related

how to install git without sudo on linux server

I tried the following to install git without sudo permissions
wget https://github.com/git/git/archive/v2.1.2.tar.gz -O git.tar.gz
tar -zxf git.tar.gz
cd git-2.1.2/
make configure
./configure --prefix=/usr/local
make install
Can anyone help me how to install git with out sudo?
As with most autoconf-ed software, you could decide to configure it with --prefix=$HOME/soft/ (or some other prefix belonging to you)
Then, since $HOME/soft/ is a directory belonging to you, you won't need any sudo for installation
Of course you'll want to add $HOME/soft/bin/ to your $PATH
You may also want to pass --sysconfdir=$HOME/etc and you might pass --program-suffix=-mine (to later run git-mine instead of git)
I strongly recommend to run configure with --help at first, and to read the INSTALL file of your particular software (before compilation time), e.g. this for git
You may also need to deal with dependencies (be aware of the dependency hell), so you might need to install other libraries (and perhaps even adjust your $LD_LIBRARY_PATH to add $HOME/soft/lib/ to it, etc).
See also GNU stow
Read the Installing GIT chapter (notably Installing from Source)
In some cases having a discussion with your sysadmin could be easier.
Simply choose a prefix that you have permission on, e.g. a folder inside your user's home:
./configure --prefix=$HOME/opt/
make install
Then you will have to add $HOME/opt/bin/ into your PATH env-var.

How do I completely uninstall git from my Linux Machine

I had installed git by downloading the tar ball and then doing the following steps
./configure --prefix=/scratch/custom/git
make
make install
But after running these commands, I still see that git is created under /usr/local as below
bash-4.1$ whereis git
git: /usr/bin/git /usr/local/git /usr/share/man/man1/git.1.gz
I would like to remove and reinstall again how do i do the same?
If make unistall doesn't work, as mentioned here, uninstalling on linux, try make install again, capturing the output.
Then go through all of the install commands and manually remove the installed files.
Also, 'make -n` may help to determine all of the installed files.

Install TCL/TK without root

I'm trying to install TCL/TK as a regular user on RedHat 5:
TCL_VERSION=8.6.1
BASE_PATH=/myownpath
tar -xzf tcl${TCL_VERSION}-src.tar.gz
cd tcl${TCL_VERSION}/unix
./configure \
--prefix=${BASE_PATH} \
--without-tzdata \
--enable-64bit
make -j9
sed -e "s#^\(TCL_SRC_DIR='\).*#\1${BASE_PATH}'#" \
-e "/TCL_B/s#='\(-L\)\?.*unix#='\1${BASE_PATH}/lib#" \
-i tclConfig.sh
make install
make install-private-headers
chmod -v 755 ${BASE_PATH}/lib/libtcl*.so
So far so good: ${BASE_PATH}/include/tcl.h exists and ${BASE_PATH}/lib/tclConfig.sh looks fine:
# String to pass to the compiler so that an extension can
# find installed Tcl headers.
TCL_INCLUDE_SPEC='-I/myownpath/include'
Then I try installing TK:
tar -xzf tk${TCL_VERSION}-src.tar.gz
cd tk${TCL_VERSION}/unix
./configure \
--prefix=${BASE_PATH} \
--enable-64bit \
--with-tcl=${BASE_PATH}/lib \
make -j9
sed -e "s#^\(TK_SRC_DIR='\).*#\1${BASE_PATH}'#" \
-e "/TK_B/s#='\(-L\)\?.*unix#='\1${BASE_PATH}/lib#" \
-i tkConfig.sh
make install
make install-private-headers
chmod -v 755 ${BASE_PATH}/lib/libtk*.so
It fails at make with the following message:
tk8.6.1/unix/../generic/tk.h:19:17: error: tcl.h: No such file or directory
What did I miss?!?
I followed below steps to install tcl, tk on Linux(Ubuntu).
please use sudo to avoid any permission related issue
Create directory of your choice say /opt/tcltk
install tcl
Create dir /opt/tcltk
Download tcl8.6.9-src.tar.gz, tk8.6.9.1-src.tar.gz from (http://www.tcl.tk/software/tcltk/download.html)
Move above these two tar files in opt/tcltk/
cd /opt/tcltk/ to install tcl8.6.9
/opt/tcltk> sudo gunzip -c tcl8.6.9-src.tar.gz | tar -xf -
cd /opt/tcltk/tcl8.6.9/unix/
/opt/tcltk/tcl8.6.9/unix> sudo ./configure --prefix=/opt/tcltk
/opt/tcltk/tcl8.6.9/unix> sudo make
Optional you can check make by executing “sudo make test”
/opt/tcltk/tcl8.6.9/unix> sudo make install
verify installation by executing "/opt/tcltk/bin/tclsh8.6" on cli
Install tk
cd /opt/tcltk/ to Extract tk tar
/opt/tcltk/>sudo gunzip -c tk8.6.9.1-src.tar.gz | tar -xf -
/opt/tcltk/tk8.6.9/unix>sudo ./configure --prefix=/opt/tcltk
/opt/degrib/tcltk/tk8.6.9/unix>sudo make
sudo make install
Please fell free to comments if there is any issue while installation
If you're wanting to install Tcl as a normal user, it's easy to do so starting with the source distribution (you'll need to pick the version you want; I recommend 8.6.1 in general right now, but that's a recommendation that's bound to change over time).
Then, change to the unix directory inside the unpacked source distribution and run ./configure; IMPORTANT: to install as non-root you must specify the --prefix option to configure to say where it is going to be installed, and you have to specify it as a full path. For example, if I was to install it beneath my home directory, I'd use:
./configure --prefix=/home/dkf
Then, just do make and make install. Or combine into one as make all install; if you're not installing as a different user, you can do it as one step. After this, I'll find I can run Tcl 8.6.1 by doing /home/dkf/bin/tclsh8.6 and the binary library and tclConfig.sh will be in /home/dkf/lib; adjust in the obvious way for the path you specify. If you do not specify the --prefix, the source distribution uses /usr/local as a default, but that's a directory which is only normally writable by the root user.
The reason you have to specify the path like this is that the path to Tcl's support scripts is baked into the binary library. (It's runtime overridable, but I don't recommend doing that when you can easily just get things right to start out with.)
When building Tk, you need a sibling Tcl build. Currently, you're recommended to have them be the same version too. You should also specify --with-tcl= and give the path to the tclConfig.sh that you just installed; while it might work without, it's easiest to just do it this way. Once you've built and installed Tcl and Tk, you (probably) don't need to keep the source trees around.
OK, I admit that I do keep them around, but I'm a data packrat…

How to create terminal commands for programs installed from source

I recently tried to install monit on Ubuntu Natty from source. Here's my code:
apt-get -y install openssl libssl-dev bison flex
mkdir src && cd src
wget http://mmonit.com/monit/dist/monit-5.3.2.tar.gz
tar xzf monit-5.3.2.tar.gz
cd monit-5.3.2
./configure --prefix=/usr/local/monit
make && make install
However, when I install Monit using apt-get I am able to call monit directly from the command line using the keyword monit. I am not able to do so when I do the install from source. The same goes for PHP.
How can I enable this feature for when I install Monit (and other Linux programs) from source?
Thanks in advance.
EDIT
I was able to solve this by doing the following:
printf "\nPATH=/usr/local/monit/bin:\${PATH}\n" >> ~/.profile
source ~/.profile
This will apply for the currently logged in user (in my case root). To make it system-wide simply replace ~/.profile with /etc/profile.
So now I can can call monit (and any other program I install from source).
Using that command to install it will put it in /usr/local/monit, which won't be in your $PATH, as others have said. There are several options besides modifying your path, though. For instance, you can create a symbolic link from the real executable to one in your path. So if the executable is /usr/local/monit/monit, you can
ln -s /usr/local/monit/monit /usr/local/bin/monit
The advantage of creating the symbolic link is it will work for all users.
You can also create an alias, but that would only work for apps that run as you.
Edit your /etc/profile to add the path /usr/local/monit to the PATH variable.
For ex, if you earlier had this.
PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin"
You could change it to
PATH="/usr/local/monit:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin"

Installing Git with non-root user account

I've already set up a Git repository on GitHub and committed a few changes from my Windows machine.
But tomorrow I'll have to work in this repository from a machine running Ubuntu with limited privilege (i.e. no 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?
You can download the git source and do ./configure --prefix=/home/user/myroot && make && make install to 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.
I don't like link-only answers, but this link 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 make and run make install and that is it.
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.
To install git and dependencies from source the following maybe useful.
Replace with the location you are installing your non-root apps and consider checking for latest versions of source code.
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
This is what I ended up doing, the main trick being the make flags:
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:
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.
A random email record I found on the internet: https://public-inbox.org/git/CAP8UFD2gKTourXUdB_9_FZ3AEECTDc1Fx1NFKzeaTZDWHC3jxA#mail.gmail.com/
A related answer is 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
Overkill workaround
Install Anaconda as a user and install git with conda.
Advantages
Anaconda can be installed as user, and a conda environment can be created which can help you to install other packages. This way you don't need to compile git from source, nor you need to install libcurl and perl, so you won't get the error
git: 'remote-https' is not a git command. See 'git --help'
after successfully compiling git.
Steps to install Anaconda, then git
read the Anaconda installation manual which points to the download page's shell script file.
Download the script file:
copy to your local machine and then copy with scp (e.g. winscp) to the Linux machine or
use a terminal on the Linux machine and issue wget https://repo.anaconda.com/archive/Anaconda3-2020.11-Linux-x86_64.sh.
add executable rights to yourself on the file by issuing chmod +x Anaconda3-2020.11-Linux-x86_64.sh
follow the installation instructions where you can also specify into which folder you want to install anaconda
after installation, chose one of the possibilities below to successfully invoke git later:
you either activate a conda environment, which is useful e.g. if you need to create different conda environments (it is common if you work with python). To activate an environment, you need to ask the installer (at the end of the installation) to add the conda initialization code into your ~/.bashrc file [see below]. Using this method, your path won't be polluted, and you will see if conda-related binaries are also in your current path. Or you can
add the installed bin's folder to your path, e.g. if you installed anaconda into /home/myusername/anaconda3, it will be in /home/myusername/anaconda3/bin. Your new executable file conda will be also there which will help you to install packages like git, python or pandoc, or
cd into the binary folder of anaconda, e.g. cd /home/myusername/anaconda3/bin, and execute the commands below.
don't forget to take into effect the new settings by, e.g., closing and opening the terminal again if you selected method 1. or 2. in point 5. If you selected 1, you will see something like (base) myusername#servername indicating you are using the base conda environment.
Now you can install git using conda by issuing conda install -c anaconda git.
Your .bashrc will contain likes like this if you told the Anaconda installer to initialize conda for you:
# content of your .bashrc in your home dir
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/home/myusername/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/home/myusername/anaconda3/etc/profile.d/conda.sh" ]; then
. "/home/myusername/anaconda3/etc/profile.d/conda.sh"
else
export PATH="/home/myusername/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<
for the latest version(which i mean git-2.25.0-rc1 or upper), you need to
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.

Resources