43

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?

4

8 回答 8

55

截至 2018 年 2 月,brew在 Ubuntu(我的是 17.10)机器上安装非常简单:

sudo apt install linuxbrew-wrapper

然后,在第一次brew执行时(只需键入brew --help),您将被要求提供两个安装选项:

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:

对于推荐的选项,输入您的密码(如果您的当前用户在sudo组中),或者,如果您希望将所有依赖项安装在您自己的主文件夹中,请点击Ctrl+ D。享受。

于 2018-02-02T13:39:46.037 回答
51

我只是尝试使用 ruby​​ 命令安装它,但不知何故,依赖关系没有解决,因此 brew 没有完全安装。但是,尝试通过克隆安装:

git clone https://github.com/Homebrew/linuxbrew.git ~/.linuxbrew

然后将以下内容添加到您的.bash_profile

export PATH="$HOME/.linuxbrew/bin:$PATH"
export MANPATH="$HOME/.linuxbrew/share/man:$MANPATH"
export INFOPATH="$HOME/.linuxbrew/share/info:$INFOPATH"

它应该工作..

于 2015-10-26T19:40:05.617 回答
18

截至 2020 年 8 月(也适用于 kali linux)

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
于 2019-07-11T05:28:33.367 回答
14

以下步骤对我有用:

  • 从 github 克隆它

    git clone https://github.com/Homebrew/linuxbrew.git ~/.linuxbrew
    
  • 使用打开您的 .bash_profile 文件vi ~/.bash_profile

  • 添加这些行

    export PATH="$HOME/.linuxbrew/bin:$PATH"
    export MANPATH="$HOME/.linuxbrew/share/man:$MANPATH"
    export INFOPATH="$HOME/.linuxbrew/share/info:$INFOPATH"
    
  • 然后在终端中输入以下行

    export PATH=$HOME/.linuxbrew/bin:$PATH
    hash -r
    

是的,它完成了。输入brew您的终端以检查它的存在。

于 2017-01-09T18:40:18.183 回答
5

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.

于 2020-12-21T19:24:35.127 回答
3

brew 现在正式支持 Linux - 请参阅Homebrew 2.0.0博客文章。如https://brew.sh所示,只需将其复制/粘贴到命令提示符中:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
于 2020-11-11T03:32:18.007 回答
2

因为所有以前的答案对我所做的 ubuntu 14.04 都不起作用,如果有人遇到同样的问题:

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"

然后

sudo apt-get install gawk
sudo yum install gawk
brew install hello

您可以点击此链接了解更多信息。

于 2017-11-14T17:39:26.037 回答
1

2019 年 10 月 - 带有 oh-my-zsh 的 WSL 上的 Ubuntu 18.04;这里的说明效果很好 -

(首先,使用sudo apt-get install build-essential curl file git安装先决条件 )

最后创建一个~/.zprofile具有以下内容的: emulate sh -c '. ~/.profile'

于 2019-10-04T09:49:03.210 回答