Can I use Homebrew on Ubuntu? - linux

I just tried to use Homebrew and Linuxbrew to install packages on my Ubuntu Server but both failed. This is how I tried to install them:
sudo apt-get install build-essential curl git m4 ruby texinfo libbz2-dev libcurl4-openssl-dev libexpat-dev libncurses-dev zlib1g-dev
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/linuxbrew/go/install)"
I got the following warning:
Warning: /home/tong/.linuxbrew/bin is not in your PATH.
I vi my bash.bashrc in home/etc and add this:
export PATH="$HOME/.linuxbrew/bin:$PATH"
export MANPATH="$HOME/.linuxbrew/share/man:$MANPATH"
export INFOPATH="$HOME/.linuxbrew/share/info:$INFOPATH"
Then I tried brew doctor but got No command 'brew' found. How am I able to use Homebrew on Ubuntu?

As of February 2018, installing brew on Ubuntu (mine is 17.10) machine is as simple as:
sudo apt install linuxbrew-wrapper
Then, on first brew execution (just type brew --help) you will be asked for two installation options:
me#computer:~/$ brew --help
==> Select the Linuxbrew installation directory
- Enter your password to install to /home/linuxbrew/.linuxbrew (recommended)
- Press Control-D to install to /home/me/.linuxbrew
- Press Control-C to cancel installation
[sudo] password for me:
For recommended option type your password (if your current user is in sudo group), or, if you prefer installing all the dependencies in your own home folder, hit Ctrl+D. Enjoy.

I just tried installing it using the ruby command but somehow the dependencies are not resolved hence brew does not completely install. But, try installing by cloning:
git clone https://github.com/Homebrew/linuxbrew.git ~/.linuxbrew
and then add the following to your .bash_profile:
export PATH="$HOME/.linuxbrew/bin:$PATH"
export MANPATH="$HOME/.linuxbrew/share/man:$MANPATH"
export INFOPATH="$HOME/.linuxbrew/share/info:$INFOPATH"
It should work..

as of august 2020 (works for kali linux as well)
sh -c "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh)"
export brew=/home/linuxbrew/.linuxbrew/bin
test -d ~/.linuxbrew && eval $(~/.linuxbrew/bin/brew shellenv)
test -d /home/linuxbrew/.linuxbrew && eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)
test -r ~/.profile && echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.profile // for ubuntu and debian

The following steps worked for me:
Clone it from github
git clone https://github.com/Homebrew/linuxbrew.git ~/.linuxbrew
Open your .bash_profile file using vi ~/.bash_profile
Add these lines
export PATH="$HOME/.linuxbrew/bin:$PATH"
export MANPATH="$HOME/.linuxbrew/share/man:$MANPATH"
export INFOPATH="$HOME/.linuxbrew/share/info:$INFOPATH"
Then type the following lines in your terminal
export PATH=$HOME/.linuxbrew/bin:$PATH
hash -r
Yes, it is done. Type brew in your terminal to check its existence.

You can just follow instructions from the Homebrew on Linux docs, but I think it is better to understand what the instructions are trying to achieve.
Understanding the installation steps can save some time
Step 1: Choose location
First of all, it is important to understand that linuxbrew will be installed on the /home directory and not inside /home/your-user (the ~ directory).
(See the reason for that at the end of answer).
Keep this in mind when you run the other steps below.
Step 2: Add linuxbrew binaries to /home :
The installation script will do it for us:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Step 3: Check that /linuxbrew was added to the relevant location
This can be done by simply navigating to /home.
Notice that the docs are showing it as a one-liner by adding test -d <linuxbrew location> before each command.
(Read more about the test command in here).
Step 4: Export relevant environment variables to terminal
We need to add linuxbrew to PATH and add some more environment variables to the current terminal.
We can just add the following exports to terminal (wait don't do it..):
export PATH="/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin${PATH+:$PATH}";
export HOMEBREW_PREFIX="/home/linuxbrew/.linuxbrew";
export HOMEBREW_CELLAR="/home/linuxbrew/.linuxbrew/Cellar";
export HOMEBREW_REPOSITORY="/home/linuxbrew/.linuxbrew/Homebrew";
export MANPATH="/home/linuxbrew/.linuxbrew/share/man${MANPATH+:$MANPATH}:";
export INFOPATH="/home/linuxbrew/.linuxbrew/share/info:${INFOPATH:-}";
Or simply run (If your linuxbrew folder is on other location then /home - change the path):
eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)
(*) Because brew command is not yet identified by the current terminal (this is what we're solving right now) we'll have to specify the full path to the brew binary: /home/linuxbrew/.linuxbrew/bin/brew shellenv
Test this step by:
1 ) Run brew from current terminal to see if it identifies the command.
2 ) Run printenv and check if all environment variables were exported and that you see /home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin on PATH.
Step 5: Ensure step 4 is running on each terminal
We need to add step 4 to ~/.profile (in case of Debian/Ubuntu):
echo "eval \$($(brew --prefix)/bin/brew shellenv)" >> ~/.profile
For CentOS/Fedora/Red Hat - replace ~/.profile with ~/.bash_profile.
Step 6: Ensure that ~/.profile or ~/.bash_profile are being executed when new terminal is opened
If you executed step 5 and failed to run brew from new terminal - add a test command like echo "Hi!" to ~/.profile or ~/.bash_profile.
If you don't see Hi! when you open a new terminal - go to the terminal preferences and ensure that the attribute of 'run command as login shell' is set.
Read more in here.
Why the installation script installs Homebrew to /home/linuxbrew/.linuxbrew - from here:
The installation script installs Homebrew to
/home/linuxbrew/.linuxbrew using sudo if possible and in your home
directory at ~/.linuxbrew otherwise. Homebrew does not use sudo
after installation. Using /home/linuxbrew/.linuxbrew allows the
use of more binary packages (bottles) than installing in your personal
home directory.
The prefix /home/linuxbrew/.linuxbrew was chosen so that users
without admin access can ask an admin to create a linuxbrew role
account and still benefit from precompiled binaries.
If you do not yourself have admin privileges, consider asking your
admin staff to create a linuxbrew role account for you with home
directory /home/linuxbrew.

Linux is now officially supported in brew - see the Homebrew 2.0.0 blog post. As shown on https://brew.sh, just copy/paste this into a command prompt:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Because all previous answers doesn't work for me for ubuntu 14.04
here what I did, if any one get the same problem:
git clone https://github.com/Linuxbrew/brew.git ~/.linuxbrew
PATH="$HOME/.linuxbrew/bin:$PATH"
export MANPATH="$(brew --prefix)/share/man:$MANPATH"
export INFOPATH="$(brew --prefix)/share/info:$INFOPATH"
then
sudo apt-get install gawk
sudo yum install gawk
brew install hello
you can follow this link for more information.

October 2019 - Ubuntu 18.04 on WSL with oh-my-zsh;
the instructions here worked perfectly -
(first, install pre-requisites using sudo apt-get install build-essential curl file git)
finally create a ~/.zprofile with the following contents:
emulate sh -c '. ~/.profile'

Whta to do
cd /home/linuxbrew/.linuxbrew/bin
./brew doctor
You will get what path to export
echo 'export PATH="/home/linuxbrew/.linuxbrew/bin:$PATH"' >> ~/.zshrc

Related

Command 'ddev' not found on WSL2/Linux with homebrew installation

I followed the installation guide for ddev on WSL 2 https://ddev.readthedocs.io/en/stable/#windows-wsl2
but when I enter ddev in the ubuntu shell I only get the error:
Command 'ddev' not found, did you mean:
command 'ddv' from deb ncbi-tools-x11 (6.1.20170106+dfsg1-8)
Try: sudo apt install <deb name>
Yes I also executed the last step multiple times, to make sure that I installed everything.
Any ideas?
I assume you installed ddev using homebrew, per those instructions. When you finish installing homebrew, it gives you instructions about how to add brew to your $PATH. I imagine you didn't do that.
==> Next steps:
- Run these two commands in your terminal to add Homebrew to your PATH:
echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> /home/gitpod/.profile
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
- Install Homebrew's dependencies if you have sudo access:
sudo apt-get install build-essential
For more information, see:
https://docs.brew.sh/Homebrew-on-Linux
- We recommend that you install GCC:
brew install gcc
- Run brew help to get started
- Further documentation:
https://docs.brew.sh
Assuming you did a brew install drud/ddev/ddev I think if you do those steps you'll find that ddev is now in your $PATH. If you echo $PATH you should see it containing /home/linuxbrew/.linuxbrew/bin, which is where both brew and ddev will be installed.

virtualenv not found in path

For some reason virtualenv is not in my path after installing with pip3. I have a fresh install of ubuntu 16.04.
sudo apt-get install pip3
pip3 install virtualenv
virtualenv # command not found!!!
edit: I also installed jupyter notebook with pip3 and its not in the path either.
Python executables are placed in ~/.local/bin/ on Ubuntu 16.04.
This location is not in $PATH so edit your .bashrc to append it there.
# .bashrc file
export PATH=$PATH:~/.local/bin
This is Ubuntu only (didn't check other distros)
TL;DR (if you used pip to install pkg) run following command
$ source ~/.profile
If you examine .profile there is a script looks like following.
(18 version. 16 version has something different)
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
PATH="$HOME/.local/bin:$PATH"
fi
which means everything under ~/.local/bin will be added to PATH.
So, if you used pip to install pkg and try to run from prompt. As long as pip created file under the folder it will let you run commands without full path.
You can restart the session too. Whichever you feel comfortable with.

-bash: /usr/bin/virtualenvwrapper.sh: No such file or directory

I can't figure out where the shell is trying to run /usr/bin/virtualenvwrapper.sh upon server login. I want virtualenvwrapper permanently uninstalled, not just removed from the shell instance. I thought I uninstalled it with pip uninstall virtualenvwrapper, but every time I log into the server I get the error -bash: /usr/bin/virtualenvwrapper.sh: No such file or directory, as if there is some sort of leftover artifact. Yesterday I did a lot of tinkering and I can't remember all the changes I made or how I made this happen. Where is it executing the search for virtualenvwrapper.sh?
SUPPLEMENTARY INFO
$ echo $PATH
/usr/lib64/qt-3.3/bin
/usr/local/bin/ibm/lsf/9.1/linux2.6-glibc2.3-x86_64/etc
/usr/local/bin/ibm/lsf/9.1/linux2.6-glibc2.3-x86_64/bin
/usr/local/bin
/bin
/usr/bin
/usr/local/sbin
/usr/sbin
/sbin/usr/local/bin/CASAVA-1.8.2/bin
/usr/local/bin/blast
/usr/local/bin/mirdeep2
/usr/local/bin/velvet
$ sudo vim ~/.bashrc
1 # .bashrc
2
3 # Source global definitions
4 if [ -f /etc/bashrc ]; then
5 . /etc/bashrc
6 fi
7
8 # User specific aliases and functions
on ubuntu 12.04 LTS, installing through pip, it is installed to
/usr/local/bin/virtualenvwrapper.sh
And if you are using Ubuntu 16.04 or later, it is installed to
~/.local/bin/virtualenvwrapper.sh
Setting up a Virtual Environment
Now open your terminal in the home directory by right clicking and choosing the option “Open in Terminal”. You can also press the CTRL, ALT, and T keys on your keyboard at the same time to open the Terminal application automatically.
You first need to create a special directory that will hold all of your virtual environments. So proceed with creating a new hidden directory called virtualenv.
$ mkdir .virtualenv
Now you should install pip for Python3.
$ sudo apt install python3-pip
Confirm the pip3 installation.
$ pip3 --version
Now install virtualenv via pip3.
$ pip3 install virtualenv
To find where your virtualenv was installed, type:
$ which virtualenv
Install virtualenvwrapper via pip3:
$ pip3 install virtualenvwrapper
We are going to modify your .bashrc file by adding a row that will adjust every new virtual environment to use Python 3. We will point virtual environments to the directory we created above (.virtualenv) and we will also point to the locations of the virtualenv and virtualenvwrapper.
Now open the .bashrc file using Vim editor.
$ vim .bashrc
If you still haven’t used the Vim editor or you don’t have it installed on your computer you should install it now. It is a widely used Linux editor, and for good reason.
$ sudo apt install vim
After you've installed Vim open the file .bashrc file by typing the vim .bashrc command in your terminal. Navigate to the bottom of the .bashrc file, press the letter i to enter the insert mode of Vim, and add these rows:
#Virtualenvwrapper settings:
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_VIRTUALENV=/home/your_username/.local/bin/virtualenv
source ~/.local/bin/virtualenvwrapper.sh
After you are done, press the esc key. Then type :wq and press enter. This command will save and exit the Vim editor. Close and reopen your terminal when you’re done.
To create a virtual environment in Python3 and activate it immediately, use this command in your terminal:
$ mkvirtualenv name_of_your_env
You should confirm that this environment is set up for Python3:
$ Python -V
To deactivate the environment use the deactivate command.
$ deactivate
To list all available virtual environments use the command workon or lsvirtualenv (same result as workon but shown in a fancy way) in your terminal:
$ workon
$ lsvirtualenv
To activate one specific environment use workon + name of your environment:
$ workon name_of_your_env
There are several useful command you might need to use someday:
Rmvirtualenv will remove a specific virtual environment located in your .virtualenv directory.
$ rmvirtualenv name_of_your_env
Cpvirtualenv will copy the existing virtual environment to a new virtual environment and activate it.
$ cpvirtualenv old_virtual_env new_virtual_env
Well done! You have now created your first isolated Python 3 environment.
There are a number of files that might be run when you login to your terminal if you are using the bash shell.
You should check ~/.bashrc, ~/.bash_profile, ~/.bash_login and ~/.profile for "/usr/bin/virtualenvwrapper.sh".
Likely one of those files is being run on login and contains the missing script which you uninstalled.
It can be that you python packages are installed somewhere else. So try:
$ which python
/home/tesla/miniconda3/bin/python
or
$ which virtualenvwrapper.sh
/home/tesla/miniconda3/bin/virtualenvwrapper.sh
To check the location of python installation. In my case I was using miniconda, therefore system was not able to find the location mentioned in the documentation.
If the above location is not /usr/local/bin/virtualenvwrapper.sh
then now use :
source /home/tesla/miniconda3/bin/virtualenvwrapper.sh
Should work.
UPDATE Nov-2022:
I would recommend using pipenv (official docs) for creating and managing virtual environments.
For anyone finding this in the future. The virtualenvwrapper.sh script is/was now located at /usr/share/virtualenvwrapper/virtualenvwrapper.sh on Ubuntu 20.04.1 LTS (at least for me in my VM).
(Sadly i can't just comment on the above post mentioning the locations so it would all be together, because new user reputation)
sudo -H pip3 install virtualenvwrapper
i ran into to similar problem where installation could not suceed because ~/.cache/pip and ~/.cache/pip/http is not owned by the current user. installing with -H or --set-home option solved my problem.
Confirmed for Ubuntu 18 , as already answered by #Tarique . The shell script virtualenvwrapper.sh for the wrapper is within - ~/.local/bin/
(base) dhankar#dhankar-1:~/opencv_cuda$ cd ~/.local/bin/
(base) dhankar#dhankar-1:~/.local/bin$ ls -ltr
total 100
-rwxr-xr-x 1 dhankar dhankar 41703 Jul 23 20:56 virtualenvwrapper.sh
-rwxr-xr-x 1 dhankar dhankar 2210 Jul 23 20:56 virtualenvwrapper_lazy.sh
-rwxr-xr-x 1 dhankar dhankar 259 Jul 23 20:56 virtualenv
I also confronted the same problem, but this worked for me: -
Create a directory to hold the virtual environments.mkdir $HOME/.virtualenvs
Add a line like export WORKON_HOME=$HOME/.virtualenvsto your
.bashrc.
Add a line like source /path/to/this/file/virtualenvwrapper.sh
to your .bashrc.
Run: source ~/.bashrc
Run: mkvirtualenv temp
This time, the "temp" environment is included.
Run: workon temp
The virtual environment is activated.
If you are on Ubuntu 20 then use the code given below in ~/.bashrc
export WORKON_HOME=~/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export VIRTUALENVWRAPPER_VIRTUALENV=~/.local/bin/virtualenv
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
source ~/.local/bin/virtualenvwrapper.sh
In my case on Ubuntu 20, I found this script in:
/usr/share/virtualenvwrapper/

What's the correct way of installing jdk on linux

I am running the debian based Crunchbang linux system and i want to install the Oracle JDK (not openjdk) on my system.
I've spent some time to google for it, but i was not able to find a clear description of how to install (and configure) it.
So here are my questions:
WHERE is the correct/best location to install the downloaded JDK? (most people prefer something like usr/lib/jvm. why?
when i have installed the jvm (i.e. copied the content of the jdk<version>.tar.gz file to the chosen location, i have to setup my system to refer to the jdk.
here I can use for example: sudo update-alternatives --install "/usr/bin/java" "java" \
"/usr/lib/jvm/jdk<version>/bin/java" 1.
i have to do the same with javac right?
finally i have to set the JAVA_HOME variable by adding the lines:
JAVA_HOME=/usr/lib/jvm/jdk<version>/
export JAVA_HOME
to the .bashrc file.
But the problem: This way i always have to update my alternatives whenever i upgrade my jdk right? How can i solve this?
Can anybody give a clear description how to install the jdk on linux systems in a clever and correct way?
thank you
You can install and stay up to date with the latest Oracle Java 7 and all you have to do is manually add the PPA repository to the Software Sources.
From http://www.webupd8.org/2012/06/how-to-install-oracle-java-7-in-debian.html:
su -
echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu precise main" | tee -a /etc/apt/sources.list
echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu precise main" | tee -a /etc/apt/sources.list
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EEA14886
apt-get update
apt-get install oracle-java7-installer
exit
For Ubuntu, http://www.webupd8.org/2012/01/install-oracle-java-jdk-7-in-ubuntu-via.html. With this, I've managed to installed JDK on my ubuntu server.
Step 1: Open Applicaction>> Accessories>> Terminal
Step 2: Type commandline as below...
sudo apt-get install openjdk-6-jdk
Step 3: Type commandline as below...
apt-cache search jdk
(Note: openjdk-6-jdk is symbolically used here you can choose jdk version as per your requirment.)
How to set "Environment Variables" for "Open jdk" in Ubuntu(Linux)?
Step 4: For "JAVA_HOME" (Environment Variable) type command as shown below, in "Terminal" using your installation path...
export JAVA_HOME=/usr/lib/jvm/java-6-openjdk
(Note: "/usr/lib/jvm/java-6-openjdk" is symbolically used here just for demostration you should use your path as per your installation.)
Step 5: For "PATH" (Environment Variable) type command as shown below, in "Terminal" using your installation path...
export PATH=/usr/lib/jvm/java-6-openjdk/bin
(Note: "/usr/lib/jvm/java-6-openjdk" is symbolically used here just for demostration you should use your path as per your installation.)
Step 6: Check for "open jdk" installation, just type command in "Terminal" as shown below java
Just make a symlink /usr/lib/jvm/jdk that points to /usr/lib/jvm/jdk<version>. Then all you have to do after updating the JDK is update the symlink to point to the new location.
In 2020 here is how we roll!
NB: This will also work for Command Line on Linux Systems.
Kudos to this dude here
Step 1:
Download the latest JDK(jdk-8u231-linux-x64.tar.gz) from this official site.
using this
wget -c --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u231-linux-x64.tar.gz
because we are installing remotely if not just download from here
Step 2:
Open the terminal (Ctrl + Alt + T) and enter the following command.
sudo mkdir /usr/lib/jvm
Step 3:
Enter the following command to change the directory.
cd /usr/lib/jvm
Step 4:
Extract the jdk-8u231-linux-x64.tar.gz file in that directory using this command.
sudo tar -xvzf ~/Downloads/jdk-8u231-linux-x64.tar.gz
According to this command, the JDK filename is jdk-8u231-linux-x64.tar.gz and which is located in the ~/Downloads folder. If your downloaded file is in any other location, change the command according to your path.
Step 5:
Enter the following command to open the environment variables file.
sudo nano /etc/environment
In the opened file, add the following bin folders to the existing PATH variable. (in my case the file was empty so i just add the content and saved).
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/jdk1.8.0_231/bin:/usr/lib/jvm/jdk1.8.0_231/db/bin:/usr/lib/jvm/jdk1.8.0_231/jre/bin"
J2SDKDIR="/usr/lib/jvm/jdk1.8.0_231"
J2REDIR="/usr/lib/jvm/jdk1.8.0_231/jre"
JAVA_HOME="/usr/lib/jvm/jdk1.8.0_231"
DERBY_HOME="/usr/lib/jvm/jdk1.8.0_231/db"
This is how your file will look after modifying...
Save the changes and close the gedit.
Step 7:
Enter the following commands to inform the system about the Java's location. Depending on your JDK version, the paths can be different.
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.8.0_231/bin/java" 0
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.8.0_231/bin/javac" 0
sudo update-alternatives --set java /usr/lib/jvm/jdk1.8.0_231/bin/java
sudo update-alternatives --set javac /usr/lib/jvm/jdk1.8.0_231/bin/javac
Step 8:
To verify the setup enter the following commands and make sure that they print the location of java and javac as you have provided in the previous step.
update-alternatives --list java
update-alternatives --list javac
Step 9:
Restart the computer (or just log-out and login) and open the terminal again. (I dint have to do this because step 10 already came through)
Step 10:
Enter the following command.
java -version
Step 11:
Enjoy!!!

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