45

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?

Yilmaz
  • 35,338
  • 10
  • 157
  • 202
Gavin Niu
  • 1,315
  • 4
  • 20
  • 27
  • 1
    Excuse me, now I have a zinc-0.3.9.tgz, and I want to install this zinc compile server, what apt command should I use? apt-get install can not locate the package and I have to download the tgz first and then install it locally. Thanks – Gavin Niu Oct 26 '15 at 19:47
  • Not sure what "my bash.bashrc in home/etc" means but .bash_profile and .bashrc are expected to be in $HOME. – ianml Oct 29 '15 at 18:30
  • `snapcraft.io` might be worth checking out – penduDev Sep 18 '18 at 04:49
  • 1
    here is the answer from the doc if someone is still looking https://docs.brew.sh/Homebrew-on-Linux – x85ms16 Oct 07 '19 at 18:58

9 Answers9

55

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.

Andrejs Cainikovs
  • 27,428
  • 2
  • 75
  • 95
  • Why is /home/linuxbrew/.linuxbrew recommended? – Porcupine Sep 16 '19 at 12:24
  • 1
    Obviously, for security reasons. `brew` will run then under its dedicated user. Think of `apache` and `www-data`, as an example. – Andrejs Cainikovs Sep 16 '19 at 14:00
  • Thanks. But I am unaware of `apache` and `www-data`. Also, what are the security concerns, given that it does not require sudo rights? – Porcupine Sep 16 '19 at 14:53
  • That's quite a big topic, which I'm pretty sure is covered on https://serverfault.com. I'd say, if your machine is not exposed to internet, but a development machine or similar, you probably should not care. – Andrejs Cainikovs Sep 16 '19 at 18:33
  • 22
    I get this error ```E: Unable to locate package linuxbrew-wrapper ``` – Panagiss Jul 18 '20 at 20:19
53

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

Lars Blumberg
  • 19,326
  • 11
  • 90
  • 127
user3307291
  • 708
  • 1
  • 8
  • 11
  • You mean I can install it just by clone it? – Gavin Niu Oct 26 '15 at 20:10
  • For cloning you need to first clean/remove the .linuxbrew that was created under your user space. Then effectively you need to execute git clone which would get the package and then include the export commands to your bash_profile file. – user3307291 Oct 26 '15 at 20:51
  • Yes it does. I just did a fresh install. What kind of error are you facing? – user3307291 Oct 26 '15 at 21:00
  • I'm not sure. what is the .bash_profile file. Do you vi it as a new file or does it locate somewhere else? – Gavin Niu Oct 26 '15 at 21:06
  • And my .linuxbrew locate in $home/tong/.linuxbrew do i need to change the export path you gave me? – Gavin Niu Oct 26 '15 at 21:08
  • 9
    Run the following commands in sequence : `1) rm -rf $home/tong/.linuxbrew` 2) `git clone https://github.com/Homebrew/linuxbrew.git ~/.linuxbrew` 3) go to your home and create .bash_profile using vi 4) paste the export commands into this file 5) After that open a new terminal window and then type in brew to see if it works – user3307291 Oct 26 '15 at 21:11
  • 2
    from https://docs.brew.sh/Linuxbrew, you can now use `sh -c "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh)"`, then add `eval $(~/.linuxbrew/bin/brew shellenv)` to your `~/.zshrc` or `~/.profile`, this will add Linuxbrew to your `PATH` – jk2K Feb 15 '19 at 06:25
18

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
Yilmaz
  • 35,338
  • 10
  • 157
  • 202
  • 1
    this is definitely the way to install homebrew on linux now. – x85ms16 Oct 07 '19 at 18:50
  • 1
    if anyone running .zsh shell, run all and replace the last line with this -- `test -r ~/.zshrc && echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.zshrc` – Gajen Sunthara May 14 '20 at 00:18
  • Warning: Linuxbrew has been merged into Homebrew. Please migrate to the following command: `/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"` – smbanaei Apr 10 '21 at 07:51
14

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.

codeX
  • 4,842
  • 2
  • 31
  • 36
7

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.

Rot-man
  • 18,045
  • 12
  • 118
  • 124
3

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)"
parsley72
  • 8,449
  • 8
  • 65
  • 98
2

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.

Kamal El-Saaid
  • 145
  • 2
  • 11
1

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'

Kiran Maniya
  • 8,453
  • 9
  • 58
  • 81
jazzdup
  • 89
  • 3
1

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
Yada
  • 71
  • 4