translated

This commit is contained in:
geekpi 2021-12-07 08:41:25 +08:00
parent e11fea9919
commit 4007bb1cff
2 changed files with 222 additions and 222 deletions

View File

@ -1,222 +0,0 @@
[#]: subject: "Installing and Using Homebrew Package Manager on Linux"
[#]: via: "https://itsfoss.com/homebrew-linux/"
[#]: author: "Abhishek Prakash https://itsfoss.com/author/abhishek/"
[#]: collector: "lujun9972"
[#]: translator: "geekpi"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Installing and Using Homebrew Package Manager on Linux
======
Homebrew, also known as Brew, is a command line package manager primarily created for macOS.
[Homebrew][1] grew quite popular among macOS users as more developers created command line tools that could be easily installed with Homebrew.
This popularity resulted in the creation of Linuxbrew, a Linux port for Homebrew. Since it is primarily Git and Ruby, and Linux and macOS are both Unix-like systems, Brew works good on both kind of operating systems.
Linuxbrew project eventually merged with Homebrew project and now you just have one Brew project called Homebrew.
Why am I calling it brew, instead of Homebrew? Because the command starts with brew. Youll see it in detail in a later section.
### Why use Homebrew package manager on Linux when you have got apt, dnf, snap etc?
I know the feeling. You already have a good [package manager][2] provided by your distribution. In addition to that, you have Snap, Flatpak and other universal package system.
Do you really need Homebrew package manager on your Linux system? The answer depends on your requirement, really.
See, apart from the distributions package manager and universal packages, youll come across situations where you need other package managers like [Pip][3] (for Python applications) and [Cargo][4] (for Rust packages).
Imagine you came across a good command line utility and want to try it. Its repository mentions that it can be installed using brew or source code only. In such a case, having brew on your system could be helpful. After all, [installing from source code][5] in the 2020s is not fashionable (and comfortable).
In other words, youll have an additional option in case you come across some interesting CLI tool that provides only brew installation option.
### Install Homebrew on Ubuntu and other Linux distributions
The installation is quite easy. You just have to make sure that you have got all the dependencies.
#### Step 1: Install dependencies
You need to have relatively newer version of gcc and glibc. You can [install build-essential package on Ubuntu][6] to get them. Apart from that, you also need to [install Git][7], Curl and procps (used for monitoring system process).
You can install all of them together like this in Ubuntu and Debian based systems:
```
sudo apt-get install build-essential procps curl file git
```
![Iinstall dependencies for Homebrew in Ubuntu/Debian][8]
For other distributions, please use your package manager and install these dependencies.
#### Step 2: Install Homebrew
You can see why you needed to [install Curl][9]. It allows you to [download the installation script file in the terminal][10].
Just enter this command:
```
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
```
When asked for RETURN key, press enter:
![Installing Homebrew on Ubuntu][11]
At the end of the script competition, it recommends to run a few commands to add it to the PATH variable. Homebrew is actually installed in your home directory and then soft linked to the /usr/local directory.
![Run the suggested command under Next steps to add Homebrew to PATh variable][12]
You can [copy and paste in terminal][13] easily. Just select the command it suggests and press Ctrl+Shift+C to copy and Ctrl+Shift+V to paste.
Alternatively, you can just copy paste this command:
```
echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> $HOME/.bash_profile
```
And then this:
```
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
```
![Adding brew commands to the PATH][14]
#### Step 3: Verify brew installation
You are almost done. Just verify that brew command is ready to run by using the brew doctor command:
```
brew doctor
```
The brew doctor command will tell you if there is any issue.
You may double verify by installing the sample hello project:
```
brew install hello
```
If you see no errors, you can enjoy the Homebrew package manager on Linux.
### Using brew command for installing, removing and managing packages
Let me quickly tell you a few brew commands you can use for installing, removing and managing packages.
Since Homebrew is installed in your home directory, you do not need sudo to run it (just like Pip and Cargo).
To install a package with brew, use the install option:
```
brew install package_name
```
There is no autocompletion for the package name here. You need to know the exact package name.
To remove a brew package, you can use either **remove** or **uninstall** option. Both works the same.
```
brew remove package_name
```
You can also list the installed brew packages with this command:
```
brew list
```
You can also remove the unneeded dependencies with the autoremove option:
```
brew autoremove
```
In the next screenshot, I had only two packages installed with brew but it also shows the dependencies installed for those packages. Even after removing the package, dependencies remained. The autoremove finally removed them.
![Listing and removing brew apckages][15]
There are a lot more brew command options but that is out of scope for this tutorial. You can always [go through their documentation][16] and explore it further.
### Removing Homebrew from Linux
This tutorial wont complete without adding the steps for removing Homebrew from your Linux system.
As per the [steps mentioned on its GitHub repository][17], you have to download and run the uninstall script using this command:
```
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"
```
Youll be asked to confirm the removal by entering the Y key.
![Removing Homebrew from Linux][18]
When the uninstallation of Homebrew completes, it lists the files and directories it has leftover:
![Remaining files after Homebrew removal][19]
I let you remove the files and directories on your own.
### Conclusion
As I explained earlier, Homebrew provides an extension to what you have already got. If you stumble upon an application that has only brew as installation method, having Homebrew installed on your Linux system will come handy.
Anything you want to add to this topic or share your question or opinion? Please use the comment section.
--------------------------------------------------------------------------------
via: https://itsfoss.com/homebrew-linux/
作者:[Abhishek Prakash][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/abhishek/
[b]: https://github.com/lujun9972
[1]: https://brew.sh/
[2]: https://itsfoss.com/package-manager/
[3]: https://itsfoss.com/install-pip-ubuntu/
[4]: https://itsfoss.com/install-rust-cargo-ubuntu-linux/
[5]: https://itsfoss.com/install-software-from-source-code/
[6]: https://itsfoss.com/build-essential-ubuntu/
[7]: https://itsfoss.com/install-git-ubuntu/
[8]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/11/install-dependencies-for-homebrew-linux.png?resize=800%2C493&ssl=1
[9]: https://itsfoss.com/install-curl-ubuntu/
[10]: https://itsfoss.com/download-files-from-linux-terminal/
[11]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/11/installing-homebrew-ubuntu.png?resize=800%2C453&ssl=1
[12]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/11/adding-homebrew-to-path-Linux.png?resize=800%2C442&ssl=1
[13]: https://itsfoss.com/copy-paste-linux-terminal/
[14]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/11/post-installation-steps-for-brew.png?resize=786%2C348&ssl=1
[15]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/11/brew-remove-packages.png?resize=800%2C572&ssl=1
[16]: https://docs.brew.sh/Manpage
[17]: https://github.com/homebrew/install#uninstall-homebrew
[18]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/11/removing-homebrew-from-Linux.png?resize=800%2C539&ssl=1
[19]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/11/remaining-files-after-homebrew-removal.png?resize=800%2C464&ssl=1

View File

@ -0,0 +1,222 @@
[#]: subject: "Installing and Using Homebrew Package Manager on Linux"
[#]: via: "https://itsfoss.com/homebrew-linux/"
[#]: author: "Abhishek Prakash https://itsfoss.com/author/abhishek/"
[#]: collector: "lujun9972"
[#]: translator: "geekpi"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
在 Linux 上安装和使用 Homebrew 包管理器
======
Homebrew也被称为 Brew是一个主要为 macOS 创建的命令行包管理器。
[Homebrew][1] 在 macOS 用户中相当流行,因为更多的开发者创造了可以用 Homebrew 轻松安装的命令行工具。
这种流行导致了 Linuxbrew 的诞生,它是 Homebrew 的一个 Linux 移植。由于它主要是 Git 和 Ruby而 Linux 和 macOS 都是类 Unix 的系统,所以 Brew 在两种操作系统上都能很好地工作。
Linuxbrew 项目最终与 Homebrew 项目合并,现在你只有一个 Brew 项目,叫做 Homebrew。
为什么我叫它brew而不是Homebrew因为命令以brew开头。你会在后面的章节中看到它的详细内容。
### 当你有 apt、dnf、snap 等软件时,为什么还要在 Linux 上使用 Homebrew 包管理器?
我知道这种感觉。你已经有一个由你的发行版提供的好的[包管理器][2]。除此之外,你还有 Snap、Flatpak 和其他通用软件包系统。
你真的需要 Homebrew 包管理器在你的 Linux 系统上吗?答案取决于你的需求。
你看,除了发行版的包管理器和通用包管理器,你会遇到需要其他包管理器的情况,比如 [Pip][3] 用于Python 应用)和 [Cargo][4] (用于 Rust 软件包)。
想象一下,你遇到了一个很好的命令行工具,想试试。它的软件库提到它可以使用 brew 或源代码来安装。在这种情况下,在你的系统上有 brew 可能会有帮助。毕竟,在 2020 年代,[从源代码安装][5]并不时髦(也不舒服)。
换句话说,如果你遇到一些有趣的命令行工具只提供 brew 安装选项,你会有一个额外的选择。
### 在 Ubuntu 和其他 Linux 发行版上安装 Homebrew
安装是相当容易的。你只需要确保你已经有了所有的依赖项。
#### 步骤 1安装依赖项
你需要有相对较新版本的 gcc 和 glibc。你可以[在 Ubuntu 上安装 build-essential 包][6]来获得它们。除此之外,你还需要[安装 Git][7]、Curl 和 procps用于监控系统进程
在基于 Ubuntu 和 Debian 的系统中,你可以像这样一起安装所有这些东西:
```
sudo apt-get install build-essential procps curl file git
```
![Iinstall dependencies for Homebrew in Ubuntu/Debian][8]
对于其他发行版,请使用你的包管理器并安装这些依赖项。
#### 步骤 2安装 Homebrew
你可以看到为什么你需要[安装 Curl][9]。它允许你[在终端下载安装脚本文件][10]。
只要输入这个命令:
```
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
```
当要求输入回车键时,请按下。
![Installing Homebrew on Ubuntu][11]
在脚本最后,它建议运行几个命令,将其添加到 PATH 变量中。Homebrew 实际上是安装在你的主目录中,然后软链接到 /usr/local 目录中。
![Run the suggested command under Next steps to add Homebrew to PATh variable][12]
你可以[在终端方便地复制和粘贴][13]。只要选择它所建议的命令,按 Ctrl+Shift+C 复制,按 Ctrl+Shift+V 粘贴。
或者,你也可以直接复制粘贴这个命令:
```
echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> $HOME/.bash_profile
```
然后是这个:
```
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
```
![Adding brew commands to the PATH][14]
#### 步骤 3验证 brew 的安装
你就快完成了。只需通过使用 brew doctor 命令来验证 brew 命令是否可以运行:
```
brew doctor
```
brew doctor 命令会告诉你是否有任何问题。
你可以通过安装示例 hello 项目再次验证:
```
brew install hello
```
如果你没有看到任何错误,你可以在 Linux 上享受 Homebrew 包管理器。
### 使用 brew 命令来安装、删除和管理软件包
让我快速告诉你几个可以用来安装、删除和管理软件包的 brew 命令。
由于 Homebrew 安装在你的主目录中,你不需要 sudo 来运行它(就像 Pip 和 Cargo
要用 brew 安装一个软件包,请使用安装选项:
```
brew install package_name
```
这里没有自动完成软件包名称的功能。你需要知道确切的软件包名称。
要删除一个 brew 软件包,你可以使用 **remove****uninstall** 选项。两者的作用是一样的。
```
brew remove package_name
```
你也可以用这个命令列出已安装的 brew 软件包:
```
brew list
```
你也可以用 autoremove 选项删除不需要的依赖:
```
brew autoremove
```
在下一张截图中,我只用 brew 安装了两个软件包但它也显示了这些软件包的依赖关系。即使在移除软件包后依赖关系仍然存在。autoremove 终于把它们删除了。
![Listing and removing brew apckages][15]
还有很多brew命令选项但这不在本教程的范围内。你可以随时[翻阅他们的文档][16]并进一步探索。
### 从Linux中删除 Homebrew
如果不加入从你的 Linux 系统中删除 Homebrew 的步骤,本教程就不完整。
根据[GitHub仓库中提到的步骤][17],你必须下载并使用这个命令运行卸载脚本:
```
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"
```
你会被要求输入 Y 键来确认删除。
![Removing Homebrew from Linux][18]
当 Homebrew 的卸载完成后,它会列出它所遗留的文件和目录:
![Remaining files after Homebrew removal][19]
我让你自己去删除这些文件和目录。
### 总结
正如我前面解释的Homebrew 为你已经有的东西提供了一个扩展。如果你偶然发现一个只有 brew 安装方式的应用,在你的 Linux 系统上安装 Homebrew 会很方便。
你对这个话题有什么要补充的,或者分享你的问题或意见?请在评论区留言。
--------------------------------------------------------------------------------
via: https://itsfoss.com/homebrew-linux/
作者:[Abhishek Prakash][a]
选题:[lujun9972][b]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/abhishek/
[b]: https://github.com/lujun9972
[1]: https://brew.sh/
[2]: https://itsfoss.com/package-manager/
[3]: https://itsfoss.com/install-pip-ubuntu/
[4]: https://itsfoss.com/install-rust-cargo-ubuntu-linux/
[5]: https://itsfoss.com/install-software-from-source-code/
[6]: https://itsfoss.com/build-essential-ubuntu/
[7]: https://itsfoss.com/install-git-ubuntu/
[8]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/11/install-dependencies-for-homebrew-linux.png?resize=800%2C493&ssl=1
[9]: https://itsfoss.com/install-curl-ubuntu/
[10]: https://itsfoss.com/download-files-from-linux-terminal/
[11]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/11/installing-homebrew-ubuntu.png?resize=800%2C453&ssl=1
[12]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/11/adding-homebrew-to-path-Linux.png?resize=800%2C442&ssl=1
[13]: https://itsfoss.com/copy-paste-linux-terminal/
[14]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/11/post-installation-steps-for-brew.png?resize=786%2C348&ssl=1
[15]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/11/brew-remove-packages.png?resize=800%2C572&ssl=1
[16]: https://docs.brew.sh/Manpage
[17]: https://github.com/homebrew/install#uninstall-homebrew
[18]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/11/removing-homebrew-from-Linux.png?resize=800%2C539&ssl=1
[19]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/11/remaining-files-after-homebrew-removal.png?resize=800%2C464&ssl=1