how to install git without sudo on linux server - linux

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.

Related

Installing RPM doesn't run all the %install actions listed in .spec

TL;DR: I made a .spec file that successfully builds a .rpm, but rpm -i <file>.rpm doesn't do all the actions I think it should. Why?
Excerpt from <file>.spec:
%install
sudo python2.7 -m pip install 'tornado<5'
...#other pip commands...
cp -r $RPM_BUILD_DIR/%{name}-%{version}/* %{buildroot}
(I know this isn't the ideal way to do it, but I'm forced to use CentOS 6 and can't upgrade the system version of python because corporate/shared environment so this was the best way I could figure out.)
All the commands under %install are correctly run when building the .rpm, so all of the pip packages get installed on the machine creating the .rpm from the .spec. rpmbuild -ba <file>.spec completes with exit 0. However, when I try to install the .noarch.rpm file that is created (on another system with identical OS/architecture), all that happens is the rpm-specified dependencies get installed and the files get shoved to the correct directories, but the other commands from %install are not run. What ends up happening is that I try to call the executable that gets made and it errors out because of the missing python packages.
RPM.org says:
Performing any tasks required before the install:
There are cases where one or more commands must be given prior to the actual installation of a package. RPM performs these commands exactly as directed by the package builder, thus eliminating a common source of problems during installations.
...Where am I supposed to specify the commands run prior to package installation if not in the %install field of the .spec file?
If you want to run commands after the rpm is installed the, you need to place those commands in the %post target.
If you want the commands to be run right before the rpm itself is installed, place the commands in the %pre target.
The commands in %install is executed when you build the .rpm, it is not run when you install the .rpm.
%install is intended to install your software onto a sandboxed directory hierarchy which should then be packaged and included into the .rpm file.
Don't run commands in %install that alters any system state or that affects anything outside the $RPM_BUILD_DIR or %{buildroot}
The %install scriptlet is run during build, not while installing.
If you wish commands to be run while installing a package, then you need to use the %post section in the spec file.
As others noted, %install is the script section within a specfile to copy the files that have already been compiled during the %build phase (which can be a no-op for python). However, others have not yet noted that sudo python2.7 -m pip install 'tornado<5' is definitely not a command that you should be using in a specfile. You need to get the python files some other way and install them into the proper locations under %{buildroot}.
RPMs should never be built as the root user nor call sudo anywhere. EVER.

How to install packages in Linux (CentOS) without root user with automatic dependency handling?

Is it possible to use RPM or YUM or any other package manager in Linux, specifically CentOS, to install a package either already downloaded or from repo to a custom location without admin/root access?
I tried building from sources, using cmake, configure, make, make install etc, but, it ended up having so many dependencies one after other.
Or are there any better alternatives?
It is possible to use yum and rpm to install any package in the repository of the distribution. Here is the recipe:
Find the package name
Use yum search.
Download
Download the package and all of its dependencies using yumdownloader (which is available on CentOS by default). You'll need to pass it --resolve to get dependency resolution. yumdownloader downloads to the current directory unless you specify a --destdir.
mkdir -p ~/rpm
yumdownloader --destdir ~/rpm --resolve vim-common
Choose a prefix location
It might be ~, ~/centos, or ~/y. If your home is slow because it is on a network file system, you can put it in /var/tmp/....
mkdir ~/centos
Extract all .rpm packages
Extract all .rpm packages to your chosen prefix location.
cd ~/centos && rpm2cpio ~/rpm/x.rpm | cpio -id
rpm2cpio outputs the .rpm file as a .cpio archive on stdout.
cpio reads it from from stdin
-i means extract (to the current directory)
-d means create missing directory
You can optionally use -v: verbose
Configure the environment
You will need to configure the environment variable PATH and LD_LIBRARY_PATH for the installed packages to work correctly. Here is the corresponding sample from my ~/.bashrc:
export PATH="$HOME/centos/usr/sbin:$HOME/centos/usr/bin:$HOME/centos/bin:$PATH"
export MANPATH="$HOME/centos/usr/share/man:$MANPATH"
L='/lib:/lib64:/usr/lib:/usr/lib64'
export LD_LIBRARY_PATH="$HOME/centos/usr/lib:$HOME/centos/usr/lib64:$L"
Edited note (thanks to #AmitNaidu for pointing out my mistake):
According to bash documentation about startup files, when connecting to a server via ssh, only .bashrc is sourced:
Invoked by remote shell daemon
Bash attempts to determine when it is being run with its standard input connected to a network connection, as when executed by the remote shell daemon, usually rshd, or the secure shell daemon sshd. If Bash determines it is being run in this fashion, it reads and executes commands from ~/.bashrc, if that file exists and is readable.
Now if you want to install a lot of packages that way, you might want to automate the process. If so, have a look at this repository.
Extra note: if you are trying to install any of gcc, zlib, make, cmake, git, fish, zsh or tmux , you should really consider using conda, see my other answer.
TL;DR Use Miniconda, conda-forge is amazing.
curl "https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh" | sh
Or, alternatively:
curl https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh > Miniconda.sh
bash Miniconda.sh -b -p ~/conda
# -b is used to specify that this is done "in batch", so skip the EULA prompt
# -p lets you specify where you want conda installed
Commonly wanted packages:
gcc conda install gcc
zlib conda install zlib
make conda install make
cmake conda install cmake
git conda install git
fish conda install -c conda-forge fish
zsh conda install -c ActivisionGameScience zsh
tmux conda install -c conda-forge tmux
This tmux has a bug with the name of the ncurse library it uses. You can work around it by going to your da/lib folder and symlinking ln -sT libtinfow.so.6.1 libtinfo.so.6
For the rest, you can try https://anaconda.org/search?q=.
I've tried for a long time to get a package manager to work well on CentOS/RedHat but without success. The best I could do was to install a Gentoo Prefix at the correct location on another CentOS with root access, then scp a .tar.xz of the whole installation to the target server (only way to get a proper gcc for Gentoo Prefix). I could emerge (build & install) packages on the target server but kept hitting problems with locals and permissions.
I recently achieved a user installation of some interesting packages using conda. Here is how to install it from the command line:
curl "https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh" | sh
If like me, your home folder is hosted on a remote drive (a network file system), you might not want to install it in your home folder, so you might want to use something like mkdir /var/tmp/lo then specify an installation folder like /var/tmp/lo/da during the installation.
You'll then be able to install quite a lot of packages, though maybe not all those you wanted. Most of the time, if it is not in the default channel, it will be in conda-forge. You can check for existing packages at https://anaconda.org/search?q=
Other package managers I've tried to use after conda:
Linuxbrew
I thought that with that it would be easy to install homebrew (linuxbrew) but their sources are messy and use hard-coded absolute path to ruby interpreter, which fails because it isn't the last version and so on and so on and I gave up.
Nix
Nix still requires you to use the /nix folder. They hard-coded it too and it's hard to sed it correctly from every download it has to do during the installation (let alone updates).
Gentoo Prefix
I expect Gentoo Prefix to be easier to install directly now that we gcc can be used on the target server. -- Ok, I tried but met permissions bugs during installation (2018-09-28):
portage.exception.OperationNotPermitted: chown(b'~/gentoo/tmp/var/tmp/portage/sys-apps/gentoo-functions-0.12/image/var', 2000, 2000)
PkgSrc
I'm going to try pkgsrc now. -- Use (older) version 64-bit EL 6.x if on CentOS 6 or if encountering (G)LibC version issues with the 7.x one. -- No luck, pkgsrc hard codes /usr/pkg/sbin and /usr/pkg/bin. So it can't be used as user, unless maybe setting up a fakechroot environment. But I've never done that and I expect usability issues.
Please comment/answer if you succeed in installing any other package manager.
Download the packages, and indicate to include dependencies with the --resolve flag.
yumdownloader --resolve openslide-tools
Iterate over all downloaded rpm files.
for i in *.rpm; do rpm2cpio $i | cpio -idv; done
the output will be stored in your present working directory $PWD/usr/*
This answer by goldilocks sounds like what you are looking for.
https://unix.stackexchange.com/a/61295
It's still not a pretty process, but seems easier than building from source.
Otherwise you might want to look into non-root package managers as an alternative to yum.
Yes it is. If the software is packaged in repos. And admin installed
PackageKit-command-not-found package.
See:
https://fedoraproject.org/wiki/Features/PackageKitCommandNotFound

unable to install git from source code

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= ....

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"

Can I install Mercurial in my home directory?

I would like to install Mercurial on a Linux system where I don't have root access.
How can I do this in a way so that I can easily uninstall Mercurial again and upgrade it when new versions are released?
Also, can I get a package for Windows that does not require admin rights to install?
Mercurial in home directory, how?
It is very easy to compile and install Mercurial in your home directory, I've done so myself.
This linked wiki-post will certainly provide some aid if you have questions;
UnixInstall
Use make install-home to install hg to your home directory, it'll put the binary file in ~/bin and associative files in ~/lib.
When uninstalling or upgrading to a new version you could either delete the files that the makefile have put in, or let make install-home (if upgrading) overwrite the existing files.
Make sure to update your $PATH after installation so that it includes ~/bin.
Install Mercurial on windows without being admin, how?
Following the link below will lead you to the download section of Mercurial. There you'll be able to find installation bundles for Windows that doesn't require administration rights.
Download
I'm aware that this question is already answered but someone could be in the situation I was and that is to have to install without C compiler and make.
Install without C compiler and make
Full description of the solution can be found on following link.
List of commands, without using make
wget http://pypi.python.org/packages/2.5/s/setuptools/setuptools-0.6c11-py2.5.egg
mkdir -p ~/software/lib/python2.5/site-packages
export PYTHONPATH=~/software/lib/python2.5/site-packages
sh setuptools-0.6c11-py2.5.egg --prefix=~/software
export PATH=${PATH}:~/software/bin
easy_install --prefix=~/software docutils
cd ~/software
wget https://www.mercurial-scm.org/release/mercurial-2.5.2.tar.gz
tar xzvf mercurial-2.5.2.tar.gz
cd mercurial-2.5.2.tar.gz
python setup.py --pure install --home="~/software" --force
cd ~/software/lib/python
mv hgext/ ../python2.5/site-packages/
mv mercurial ../python2.5/site-packages/
mv mercurial-2.5.2.egg-info ../python2.5/site-packages/
Append following lines to .bashrc:
export PYTHONPATH=~/software/lib/python2.5/site-packages
export PATH=${PATH}:~/software/bin
Check:
~$ hg
Mercurial Distributed SCM
etc...
Linux
The Mercurial source comes with a Makefile that has a local target. If you run this, then you'll build the C extensions in-place:
$ make local
... (lots of output) ...
python hg version
Mercurial Distributed SCM (version 5b66e55c0d93+20111216)
(see https://www.mercurial-scm.org for more information)
Copyright (C) 2005-2011 Matt Mackall and others
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
You will need the Python header files, they typically come in a python-dev package. You can then symlink the hg script into a directory in your PATH. I use ~/bin for this:
$ cd ~/bin
$ ln -s ../src/mercurial/hg
You can now run hg from any directory.
If you want to uninstall Mercurial, it's as simple as deleting the directory where you did the compile. Upgrading is also easy: unpack a new release in the directory and run make local again. You can also use the newly install Mercurial to clone the Mercurial repository itself:
$ hg clone https://www.mercurial-scm.org/repo/hg
$ cd hg
$ make local
This gives you a version of Mercurial from the default branch. Use hg update stable before compiling if you want a build from the stable branch instead. That branch is only updated with bugfixes.
Windows
On that platform, you can use a the Inno setup installers. They do not require admin rights. You can couple that with a portable version of TortoiseHg if you like.

Resources