mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-26 21:30:55 +08:00
commit
f9334681ce
@ -1,281 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( nophDog)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Make the switch from Mac to Linux easier with Homebrew)
|
||||
[#]: via: (https://opensource.com/article/20/6/homebrew-linux)
|
||||
[#]: author: (Matthew Broberg https://opensource.com/users/mbbroberg)
|
||||
|
||||
Make the switch from Mac to Linux easier with Homebrew
|
||||
======
|
||||
Whether you want to ease your migration from Mac to Linux or just don't
|
||||
like the standard Linux package managers, give Homebrew a try.
|
||||
![Digital images of a computer desktop][1]
|
||||
|
||||
The [Homebrew][2] project began its life as an unofficial Linux-style package manager for the Mac. Its users quickly fell in love with its friendly interface and helpful prompts, and—in what may seem like a strange twist of fate—it got ported to Linux.
|
||||
|
||||
At first, there were two separate projects for macOS and Linux (Homebrew and Linuxbrew), but now Homebrew's core manages both operating systems. Because I've been on a journey to [migrate from Mac to Linux][3], I have been looking at how my favorite open source applications for macOS perform on Linux, and I've been happy to find that Homebrew's support for Linux truly shines.
|
||||
|
||||
### Why Homebrew on Linux?
|
||||
|
||||
A reasonable first response to Homebrew from long-time Linux users is: "Why not just use…" where the next word is a package manager for their preferred version of Linux. Debian-based systems already have `apt`, Fedora-systems have `dnf` and `yum`, and projects like Flatpak and AppImage work to span the gap by running smoothly on both. I have spent a decent amount of time using all these technologies, and I have to say each one is powerful in its own right.
|
||||
|
||||
So why do I [stick with Homebrew][4]? First off, it's incredibly familiar to me. I'm already learning a lot as I transition to more open source alternatives for my past proprietary tools, and keeping something familiar—like Homebrew—helps me focus on learning one thing at a time instead of being overwhelmed by all the differences between operating systems.
|
||||
|
||||
Also, I have yet to see a package manager that is as kind to the user as Homebrew. Commands are well organized, as the default Help output shows:
|
||||
|
||||
|
||||
```
|
||||
$ brew -h
|
||||
Example usage:
|
||||
brew search [TEXT|/REGEX/]
|
||||
brew info [FORMULA...]
|
||||
brew install FORMULA...
|
||||
brew update
|
||||
brew upgrade [FORMULA...]
|
||||
brew uninstall FORMULA...
|
||||
brew list [FORMULA...]
|
||||
|
||||
Troubleshooting:
|
||||
brew config
|
||||
brew doctor
|
||||
brew install --verbose --debug FORMULA
|
||||
|
||||
Contributing:
|
||||
brew create [URL [--no-fetch]]
|
||||
brew edit [FORMULA...]
|
||||
|
||||
Further help:
|
||||
brew commands
|
||||
brew help [COMMAND]
|
||||
man brew
|
||||
<https://docs.brew.sh>
|
||||
```
|
||||
|
||||
This short output might be mistaken as a limitation, but a quick look inside any of the subcommands reveals a wealth of functionality. The list above is just 23 lines long, but the `install` subcommand has a whopping 79 lines of information available for the advanced user:
|
||||
|
||||
|
||||
```
|
||||
$ brew --help | wc -l
|
||||
23
|
||||
$ brew install --help | wc -l
|
||||
79
|
||||
```
|
||||
|
||||
It has options for ignoring or installing dependencies, choosing to build from source and with what compiler, and using exact upstream Git commits versus the official "bottled" version of the application. Suffice it to say, Homebrew is for experts and novices alike.
|
||||
|
||||
### Get started with Homebrew on Linux
|
||||
|
||||
If you want to give Homebrew a try, there is a great one-liner script to install it on Mac or Linux:
|
||||
|
||||
|
||||
```
|
||||
`$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"`
|
||||
```
|
||||
|
||||
This command executes the Homebrew installer script immediately. If you are more cautious, you can `curl` the file, then run it manually after a review:
|
||||
|
||||
|
||||
```
|
||||
$ curl -fsSL <https://raw.githubusercontent.com/Homebrew/install/master/install.sh> \--output homebrew_installer.sh
|
||||
$ more homebrew_installer.sh # review the script until you feel comfortable
|
||||
$ bash homebrew_installer.sh
|
||||
```
|
||||
|
||||
The Linux instructions include configurations for dotfiles, particularly `~/.profile` on Debian systems and `~/.bash_profile` on Fedora:
|
||||
|
||||
|
||||
```
|
||||
$ test -d /home/linuxbrew/.linuxbrew && eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)
|
||||
$ test -r ~/.bash_profile && echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.bash_profile
|
||||
$ echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.profile
|
||||
```
|
||||
|
||||
To confirm the installation, the Homebrew team provides an empty `hello` formula for testing:
|
||||
|
||||
|
||||
```
|
||||
$ brew install hello
|
||||
==> Downloading <https://linuxbrew.bintray.com/bottles/hello-2.10.x86\_64\_linux.bottle.tar.gz>
|
||||
######################################################################## 100.0%
|
||||
==> Pouring hello-2.10.x86_64_linux.bottle.tar.gz
|
||||
🍺 /home/linuxbrew/.linuxbrew/Cellar/hello/2.10: 52 files, 595.6KB
|
||||
```
|
||||
|
||||
It looks like my installation is working without any issues, so I'll explore a little more.
|
||||
|
||||
### Brew for command-line utilities
|
||||
|
||||
Homebrew boasts of being an application that "installs the stuff you need that [Linux] didn't" by default.
|
||||
|
||||
You use the `brew` command to install any of the command-line utilities packaged up in Homebrew. These package definitions are called "formulae," and they are compiled and shared through "bottles." There is a host of other beer-oriented terminology in the Homebrew universe, but the package manager's main takeaway is to make software easily accessible.
|
||||
|
||||
What kind of software? Think about the things that come in handy for nerds like me (and, since you're reading this, probably you, too). For example, the handy `tree` command that shows directory structures or `pyenv`, which I use to [manage multiple versions of Python on a Mac][5].
|
||||
|
||||
You can see all formulae available using the `search` command, and adding the `wc` command shows how many are available:
|
||||
|
||||
|
||||
```
|
||||
# -l counts the number of lines
|
||||
$ brew search | wc -l
|
||||
5087
|
||||
```
|
||||
|
||||
There are over 5,000 formulae to date, which is an incredible amount of software. The caveat is that not every formula will run on Linux. There is a section in the output of `brew search --help` that shows flags to filter software by the operating system it runs on. It launches each operating system's repository list to a browser. I'm running Fedora, so I'll give it a try with:
|
||||
|
||||
|
||||
```
|
||||
`$ brew search --fedora tree`
|
||||
```
|
||||
|
||||
The browser loads `https://apps.fedoraproject.org/packages/s/tree`, which shows the options available for Fedora. There are other ways to browse, as well. Formulae are codified and centralized into the core repositories that are split out by operating system (Mac in [Homebrew Core][6] and [Linux Core][7] for Linux bits). They are also available through the Homebrew API and [listed on the website][8].
|
||||
|
||||
Even with all these options, I still find most of my new tools through recommendations from other users. Here are some of my favorites, if you're looking for inspiration:
|
||||
|
||||
* `pyenv`, `rbenv`, and `nodenv` to manage Python, Ruby, and Node.js versions (respectively)
|
||||
* `imagemagick` for scriptable image edits
|
||||
* `pandoc` for scriptable document conversions (I often switch from .docx to .md or .html)
|
||||
* `hub` for a [better Git experience][9] for GitHub users
|
||||
* `tldr` for examples of how to use a command-line utility
|
||||
|
||||
|
||||
|
||||
To explore Homebrew, take a look at [tldr pages][10], which is a user-friendly alternative to scrolling through an application's man pages. Confirm it's available by running `search`:
|
||||
|
||||
|
||||
```
|
||||
$ brew search tldr
|
||||
==> Formulae
|
||||
tldr ✔
|
||||
```
|
||||
|
||||
Success! The checkmark lets you know it is available. Now you can install it:
|
||||
|
||||
|
||||
```
|
||||
$ brew install tldr
|
||||
==> Downloading <https://linuxbrew.bintray.com/bottles/tldr-1.3.0\_2.x86\_64\_linux.bottle.1.tar.gz>
|
||||
######################################################################## 100.0%
|
||||
==> Pouring tldr-1.3.0_2.x86_64_linux.bottle.1.tar.gz
|
||||
🍺 /home/linuxbrew/.linuxbrew/Cellar/tldr/1.3.0_2: 6 files, 63.2KB
|
||||
```
|
||||
|
||||
Homebrew serves up prebuilt binaries, so you don't have to build from source code on your local machine. That saves a lot of time and CPU fan noise. Another thing I appreciate about Homebrew is that you can appreciate this feature without understanding exactly what it means. If you prefer to build it yourself, use the `-s` or `--build-from-source` flag with `brew install` to compile the formula from source (even if a bottle exists).
|
||||
|
||||
Similarly, the complexity under the hood can be interesting. Running `info` on `tldr` shows how dependency management happens, where the source code of the formula sits on disk, and even the public analytics are available:
|
||||
|
||||
|
||||
```
|
||||
$ brew info tldr
|
||||
tldr: stable 1.3.0 (bottled), HEAD
|
||||
Simplified and community-driven man pages
|
||||
<https://tldr.sh/>
|
||||
Conflicts with:
|
||||
tealdeer (because both install `tldr` binaries)
|
||||
/home/linuxbrew/.linuxbrew/Cellar/tldr/1.3.0_2 (6 files, 63.2KB) *
|
||||
Poured from bottle on 2020-06-08 at 15:56:15
|
||||
From: <https://github.com/Homebrew/linuxbrew-core/blob/master/Formula/tldr.rb>
|
||||
==> Dependencies
|
||||
Build: pkg-config ✔
|
||||
Required: libzip ✔, curl ✔
|
||||
==> Options
|
||||
\--HEAD
|
||||
Install HEAD version
|
||||
==> Analytics
|
||||
install: 197 (30 days), 647 (90 days), 1,546 (365 days)
|
||||
install-on-request: 197 (30 days), 646 (90 days), 1,546 (365 days)
|
||||
build-error: 0 (30 days)
|
||||
```
|
||||
|
||||
### One limitation from Mac to Linux
|
||||
|
||||
On macOS, the Homebrew `cask` subcommand offers users a way to install and manage entire applications using the same great command-line utility. Unfortunately, `cask` does not yet work on any Linux distributions. I found this out while trying to install an open source tool:
|
||||
|
||||
|
||||
```
|
||||
$ brew cask install tusk
|
||||
Error: Installing casks is supported only on macOS
|
||||
```
|
||||
|
||||
I asked about it [on the forum][11] and got some quick feedback from other users. In short, the options are to:
|
||||
|
||||
* Fork the project, build the feature, and show others that it's worthwhile
|
||||
* Write a formula for the application and build from source
|
||||
* Create a third-party repository for the application
|
||||
|
||||
|
||||
|
||||
The last one is the most interesting to me. Homebrew manages third-party repositories by [creating and maintaining "taps"][12] (another beer-influenced term). Taps are worth exploring as you get more familiar with the system and want to add to the ecosystem.
|
||||
|
||||
### Backing up Homebrew installs
|
||||
|
||||
One of my favorite Homebrew features is how you can back up your installation just like any other [dotfile in version control][13]. For this process, Homebrew offers a `bundle` subcommand that holds a `dump` subcommand that generates a Brewfile. This file is a reusable list of all your currently installed tools. To generate a Brewfile from your installation, go into whichever folder you want to use and run:
|
||||
|
||||
|
||||
```
|
||||
$ cd ~/Development/dotfiles # This is my dotfile folder
|
||||
$ brew bundle dump
|
||||
$ ls Brewfile
|
||||
Brewfile
|
||||
```
|
||||
|
||||
When I change machines and want to set up the same applications on it, I go to the folder with the Brewfile and reinstall them with:
|
||||
|
||||
|
||||
```
|
||||
$ ls Brewfile
|
||||
Brewfile
|
||||
$ brew bundle
|
||||
```
|
||||
|
||||
It will install all the listed formulae on my new machine.
|
||||
|
||||
#### Brewfile management across Mac and Linux
|
||||
|
||||
The Brewfile is a great way to backup your existing installation, but what if something on Mac doesn't run on Linux or vice versa? What I have found is that Homebrew will gracefully ignore the lines that don't work on a given operating system, whether Mac or Linux. As it comes across incompatible requests (like asking brew to install casks on Linux), it skips them and continues on its way:
|
||||
|
||||
|
||||
```
|
||||
$ brew bundle --file=Brewfile.example
|
||||
|
||||
Skipping cask licecap (on Linux)
|
||||
Skipping cask macdown (on Linux)
|
||||
Installing fish
|
||||
Homebrew Bundle complete! 1 Brewfile dependency now installed.
|
||||
```
|
||||
|
||||
To keep my configuration as simple as possible, I use the same Brewfile across both operating systems and haven't run into an issue since it installs the OS-specific version each time I run it.
|
||||
|
||||
### Homebrew for package management
|
||||
|
||||
Homebrew has been my go-to manager for command-line utilities, and its familiarity makes my Linux experience that much more enjoyable. Homebrew keeps me organized and up to date, and I continue to appreciate its balance between ease of use and depth of functionality. I prefer to keep package management details to the minimal amount of information a user needs to know, and most people will benefit from that. If you're already comfortable with Linux package managers, Homebrew may come off as simple, but looking a little deeper reveals its advanced options that go far beyond what's in this article.
|
||||
|
||||
There are a lot of package management options for Linux users. If you are coming from the world of macOS, Homebrew will feel like home.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/6/homebrew-linux
|
||||
|
||||
作者:[Matthew Broberg][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://opensource.com/users/mbbroberg
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/computer_desk_home_laptop_browser.png?itok=Y3UVpY0l (Digital images of a computer desktop)
|
||||
[2]: https://brew.sh/
|
||||
[3]: https://opensource.com/article/19/10/why-switch-mac-linux
|
||||
[4]: https://opensource.com/article/20/6/homebrew-mac
|
||||
[5]: https://opensource.com/article/20/4/pyenv
|
||||
[6]: https://github.com/Homebrew/homebrew-core
|
||||
[7]: https://github.com/Homebrew/linuxbrew-core
|
||||
[8]: https://formulae.brew.sh/formula/
|
||||
[9]: https://opensource.com/article/20/3/github-hub
|
||||
[10]: https://github.com/tldr-pages/tldr
|
||||
[11]: https://discourse.brew.sh/t/add-linux-support-to-existing-cask/5766
|
||||
[12]: https://docs.brew.sh/How-to-Create-and-Maintain-a-Tap
|
||||
[13]: https://opensource.com/article/19/3/move-your-dotfiles-version-control
|
@ -0,0 +1,276 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( nophDog)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Make the switch from Mac to Linux easier with Homebrew)
|
||||
[#]: via: (https://opensource.com/article/20/6/homebrew-linux)
|
||||
[#]: author: (Matthew Broberg https://opensource.com/users/mbbroberg)
|
||||
|
||||
Homebrew 让你从 Mac 切换到 Linux 更轻松
|
||||
======
|
||||
不管你是想要更舒服地从 Mac 搬到 Linux,还是不满意常规的 Linux 包管理器,都可以试试 Homebrew。
|
||||
![Digital images of a computer desktop][1]
|
||||
|
||||
[Homebrew][2] 项目最初是为了给 Mac 用户提供一个非官方的类 Linux 包管理器。用户很快就爱上了它友好的界面以及帮助性的提示,而且 —— 真是爱恨纠缠 —— 它已经被移植到 Linux 系统。
|
||||
|
||||
一开始,macOS 和 Linux 有两个分开的项目(Homebrew 与 Linuxbrew),但是目前在两个操作系统上,都是由 Homebrew 核心管理。由于我正 [从 Mac 切换到 Linux][3],所以一直在研究我在 macOS 最常用的开源软件在 Linux 表现如何,最终,我很高兴地发现 Homebrew 也支持 Linux,太赞了!
|
||||
|
||||
### 为什么要在 Linux 使用 Homebrew 呢?
|
||||
|
||||
长期的 Linux 用户对 Homebrew 的第一反应是:“为什么不用......呢”,省略号代表他们喜欢的 Linux 包管理器。基于 Debian 的系统早就有了 `apt`,基于 Fedora 的系统则有 `dnf` 和 `yum`,并且像 Flatpak 跟 AppImage 这样的项目,在两种系统上都能流畅运行。我花了不少时间尝试这些技术,不得不说它们都很强大。
|
||||
|
||||
那我为什么还要 [坚持使用 Homebrew][4] 呢?首先,我对它非常熟悉。在为我过去使用的专利软件寻找替代品的过程中,我已经学会了许多使用方法,而且越来越熟练 —— 就像我使用 Homebrew 一样 —— 让我专注于一次学习一件事情,而不会被不同系统间的差异搞垮。
|
||||
|
||||
此外,我没有看到哪一个包管理器像 Homebrew 一样,对用户如此友好。命令井井有条,默认的帮助命令显示如下:
|
||||
|
||||
```
|
||||
$ brew -h
|
||||
Example usage:
|
||||
brew search [TEXT|/REGEX/]
|
||||
brew info [FORMULA...]
|
||||
brew install FORMULA...
|
||||
brew update
|
||||
brew upgrade [FORMULA...]
|
||||
brew uninstall FORMULA...
|
||||
brew list [FORMULA...]
|
||||
|
||||
Troubleshooting:
|
||||
brew config
|
||||
brew doctor
|
||||
brew install --verbose --debug FORMULA
|
||||
|
||||
Contributing:
|
||||
brew create [URL [--no-fetch]]
|
||||
brew edit [FORMULA...]
|
||||
|
||||
Further help:
|
||||
brew commands
|
||||
brew help [COMMAND]
|
||||
man brew
|
||||
<https://docs.brew.sh>
|
||||
```
|
||||
|
||||
过于简短的输入可能会被误解成它的缺陷,但是你仔细看看每一个子命令,都有很丰富的功能。虽然这一列只有短短 23 行,但对进阶用户来说,光是子命令 `install` 就包含整整 79 行信息量:
|
||||
|
||||
|
||||
```
|
||||
$ brew --help | wc -l
|
||||
23
|
||||
$ brew install --help | wc -l
|
||||
79
|
||||
```
|
||||
|
||||
忽视或者安装依赖,用什么编译器从源码编译,使用上游 Git 提交或者官方 “bottled” 版应用,这些你都可以选择。总而言之,Homebrew 即适合新手,也同样能满足老鸟。
|
||||
|
||||
### 开始在 Linux 使用 Homebrew
|
||||
|
||||
如果你想要试着使用 Homebrew,可以用这个一行脚本在 Mac 或者 Linux 上进行安装:
|
||||
|
||||
```
|
||||
`$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"`
|
||||
```
|
||||
|
||||
这条命令会立即开始安装 Homebrew。如果你比较谨慎,可以使用 `curl` 将文件下载到本地,检查完毕之后再运行。
|
||||
|
||||
```
|
||||
$ curl -fsSL <https://raw.githubusercontent.com/Homebrew/install/master/install.sh> \--output homebrew_installer.sh
|
||||
$ more homebrew_installer.sh # review the script until you feel comfortable
|
||||
$ bash homebrew_installer.sh
|
||||
```
|
||||
|
||||
对 Linux 的安装指导包括如何配置点文件,尤其是 Debian 系统的 `~/.profile` 和 Fedora 系统的 `~/.bash_profile`。
|
||||
|
||||
|
||||
```
|
||||
$ test -d /home/linuxbrew/.linuxbrew && eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)
|
||||
$ test -r ~/.bash_profile && echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.bash_profile
|
||||
$ echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.profile
|
||||
```
|
||||
|
||||
为了确认已经安装好,Homebrew 团队提供一个空的 `hello` formulae 供测试:
|
||||
|
||||
|
||||
```
|
||||
$ brew install hello
|
||||
==> Downloading <https://linuxbrew.bintray.com/bottles/hello-2.10.x86\_64\_linux.bottle.tar.gz>
|
||||
######################################################################## 100.0%
|
||||
==> Pouring hello-2.10.x86_64_linux.bottle.tar.gz
|
||||
🍺 /home/linuxbrew/.linuxbrew/Cellar/hello/2.10: 52 files, 595.6KB
|
||||
```
|
||||
|
||||
It looks like my installation is working without any issues, so I'll explore a little more.
|
||||
看起来安装毫无问题,那我来试试。
|
||||
|
||||
### Brew for command-line utilities
|
||||
### 命令行工具 Brew
|
||||
|
||||
Homebrew 宣称自己默认只 “安装你需要但 [Linux] 不需要的东西”。
|
||||
|
||||
在 Homebrew 中,你可以用 `brew` 命令安装任何命令行软件。这些包的定义文件叫做 “formulae”,而且它们是编译好的文件,通过 “bottles” 共享。在 Homebrew 的世界里,还有许多 “beer-oriented” 术语,但这个包管理器主要目的是让软件便于使用。
|
||||
|
||||
什么样的软件呢?对我这样的技术玩家(既然你已经在读这篇文章,估计你也是)来说最方便的东西。例如,便利的 `tree` 命令,可以展示目录结构,或者 `pyenv`,我用来 [在 Mac 管理不同版本 Python][5]。
|
||||
|
||||
你可以用 `search` 命令查看所有可以安装的 formulae,在后面通过 `wc` 命令看看一共有多少:
|
||||
|
||||
|
||||
```
|
||||
# -l counts the number of lines
|
||||
$ brew search | wc -l
|
||||
5087
|
||||
```
|
||||
|
||||
迄今为止,一共有 5000 多个 formulae,这囊括了很多软件。需要注意的是:并非所有 formula 都能在 Linux 运行。在 `brew search --help` 输出中有一部分提到可以通过操作系统标识来筛选软件。它会在浏览器打开用于每一个操作系统的软件仓库。我运行的是 Fedora,所以我打算试一试:
|
||||
|
||||
|
||||
```
|
||||
`$ brew search --fedora tree`
|
||||
```
|
||||
|
||||
浏览器打开了网址 `https://apps.fedoraproject.org/packages/s/tree`,向我展示了所有 Fedora 的可用选项。你也可以通过其它方法进行浏览。Formulae 集中整理到由操作系统划分的核心仓库当中(Mac 在 [Homebrew Core][6],Linux 在 [Linux Core][7])。同样也可以通过 Homebrew API [在网页显示][8]。
|
||||
|
||||
尽管已经安装好这些软件,我又通过其它用户的推荐找到很多新工具。我列出一些我最喜欢的工具,你可以在里面找点灵感:
|
||||
|
||||
* `pyenv`、`rbenv` 和 `nodenv` 用来管理(相应的) Python、Ruby 和 Node.js 版本
|
||||
* `imagemagick` 用于脚本化编辑图片
|
||||
* `pandoc` 用于脚本化转换文档格式(我通常将 .docx 文件转成 .md 或者 .html)
|
||||
* `hub` 为 GitHub 用户提供 [更好的 Git 体验][9]
|
||||
* `tldr` 展示命令工具的用法
|
||||
|
||||
|
||||
想要深入了解 Homebrew,可以去 [trldr 页面][10] 看看,比起应用的 man 页面,它要友好得多。使用 `search` 命令确认你可以安装:
|
||||
|
||||
```
|
||||
$ brew search tldr
|
||||
==> Formulae
|
||||
tldr ✔
|
||||
```
|
||||
|
||||
太好了!勾号说明你可以安装。那么继续吧:
|
||||
|
||||
|
||||
```
|
||||
$ brew install tldr
|
||||
==> Downloading <https://linuxbrew.bintray.com/bottles/tldr-1.3.0\_2.x86\_64\_linux.bottle.1.tar.gz>
|
||||
######################################################################## 100.0%
|
||||
==> Pouring tldr-1.3.0_2.x86_64_linux.bottle.1.tar.gz
|
||||
🍺 /home/linuxbrew/.linuxbrew/Cellar/tldr/1.3.0_2: 6 files, 63.2KB
|
||||
```
|
||||
|
||||
Homebrew 提供编译好的二进制文件,所以你也不必在本地机器上编译源码。这能节省很多时间,也不用听 CPU 风扇的噪声。我同样欣赏 Homebrew 的另外一点,你不完全理解每一个选项的含义也不会影响正常使用。若你想自己编译,可以在 `brew install` 命令后面加上 `-s` 或者 `--build-from-source` 标识,这样就能从源码编译 formula(即便已经有一个 bottle 存在)。
|
||||
|
||||
同样,软件之后的复杂度也很有意思。使用 `info` 查看 `tldr` 软件的依赖管理,formula 源代码在磁盘上的分布,甚至还能查看公开数据。
|
||||
|
||||
|
||||
```
|
||||
$ brew info tldr
|
||||
tldr: stable 1.3.0 (bottled), HEAD
|
||||
Simplified and community-driven man pages
|
||||
<https://tldr.sh/>
|
||||
Conflicts with:
|
||||
tealdeer (because both install `tldr` binaries)
|
||||
/home/linuxbrew/.linuxbrew/Cellar/tldr/1.3.0_2 (6 files, 63.2KB) *
|
||||
Poured from bottle on 2020-06-08 at 15:56:15
|
||||
From: <https://github.com/Homebrew/linuxbrew-core/blob/master/Formula/tldr.rb>
|
||||
==> Dependencies
|
||||
Build: pkg-config ✔
|
||||
Required: libzip ✔, curl ✔
|
||||
==> Options
|
||||
\--HEAD
|
||||
Install HEAD version
|
||||
==> Analytics
|
||||
install: 197 (30 days), 647 (90 days), 1,546 (365 days)
|
||||
install-on-request: 197 (30 days), 646 (90 days), 1,546 (365 days)
|
||||
build-error: 0 (30 days)
|
||||
```
|
||||
|
||||
### 从 Mac 到 Linux 的一点不足
|
||||
|
||||
在 macOS,Homebrew 的 `cask` 子命令可以让用户完全使用命令行安装、管理图形界面软件。不幸的是,`cask` 只在部分 Linux 发行版有效。我在安装一个开源工具时遇到了问题:
|
||||
|
||||
|
||||
```
|
||||
$ brew cask install tusk
|
||||
Error: Installing casks is supported only on macOS
|
||||
```
|
||||
|
||||
我在 [论坛][11] 提问,迅速得到其他用户的一些反馈。总结一下,方案如下:
|
||||
|
||||
* 复刻该项目,构建这个特性,然后告诉别人值得这样做
|
||||
* 给该软件写一个 formula,从源代码编译
|
||||
* 为该软件创建一个第三方仓库
|
||||
|
||||
|
||||
对我来说还有最后一件很有意思的事情。Homebrew 通过 [创建并维护 “taps”][12] (另一个 beer-influenced 名词)管理第三方仓库。当你对系统越来越熟悉时,你会将 Taps 加入这个生态,花点时间研究它能让你受益匪浅。
|
||||
|
||||
### 备份 Homebrew 的安装记录
|
||||
|
||||
我最中意的 Homebrew 特性之一就是你可以像其它任何 [版本控制工具备份点文件][13] 一样备份你的安装记录。为了实现这个目的,Homebrew 提供 `bundle` 子命令,它有一个子命令叫 `dump` 可以生成一份 Brewfile。这个文件包含你目前所有安装的工具列表,可以反复使用。进入你想使用的目录然后运行命令,它会根据你所安装的软件生成 Brewfile:
|
||||
|
||||
|
||||
```
|
||||
$ cd ~/Development/dotfiles # This is my dotfile folder
|
||||
$ brew bundle dump
|
||||
$ ls Brewfile
|
||||
Brewfile
|
||||
```
|
||||
|
||||
当我换了一台机器,想要安装一样的软件时,进入含有 Brewfile 的文件夹,然后重新安装:
|
||||
|
||||
|
||||
```
|
||||
$ ls Brewfile
|
||||
Brewfile
|
||||
$ brew bundle
|
||||
```
|
||||
|
||||
它会在我的新机器上安装所有列出的 formulae。
|
||||
|
||||
#### 在 Mac 和 Linux 同时管理 Brewfile
|
||||
|
||||
Brewfile 非常适合备份你目前的安装记录,但是如果某些在 Mac 上运行的软件无法运行在 Linux 呢?或者刚好相反?我发现不管是 Mac 还是 Linux,如果软件无法在当前操作系统运行,Homebrew 会优雅地忽略那一行。如果它遇到不兼容的请求(正如使用 brew 在 Linux 安装 cask),它会选择跳过,继续安装过程:
|
||||
|
||||
|
||||
```
|
||||
$ brew bundle --file=Brewfile.example
|
||||
|
||||
Skipping cask licecap (on Linux)
|
||||
Skipping cask macdown (on Linux)
|
||||
Installing fish
|
||||
Homebrew Bundle complete! 1 Brewfile dependency now installed.
|
||||
```
|
||||
|
||||
为了尽量保持配置文件的简洁,我在跨操作系统时使用同一份 Brewfile,因为它只安装与操作系统相关的版本,所以我一直没有遇到任何问题。
|
||||
|
||||
### 使用 Homebrew 管理软件包
|
||||
|
||||
Homebrew 已经成了我必备的命令行工具,由于我很熟悉它,所以在 Linux 上的体验也充满乐趣。Homebrew 让我的工具井井有条,并且时刻保持更新,我愈发欣赏它在实用性与功能上找到的平衡点。我喜欢只保留用户必要的包管理信息,大多数人能够从中受益。如果你对目前的 Linux 包管理起很满意,Homebrew 可能会让你觉得很基础,但是你要去深入研究,发掘本文没有提到的高级用法。
|
||||
|
||||
对 Linux 用户来说,他们有很多包管理器可以选择。如果你来自 MacOS,Homebrew 会让你宾至如归。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/6/homebrew-linux
|
||||
|
||||
作者:[Matthew Broberg][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/nophDog)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/mbbroberg
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/computer_desk_home_laptop_browser.png?itok=Y3UVpY0l (Digital images of a computer desktop)
|
||||
[2]: https://brew.sh/
|
||||
[3]: https://opensource.com/article/19/10/why-switch-mac-linux
|
||||
[4]: https://opensource.com/article/20/6/homebrew-mac
|
||||
[5]: https://opensource.com/article/20/4/pyenv
|
||||
[6]: https://github.com/Homebrew/homebrew-core
|
||||
[7]: https://github.com/Homebrew/linuxbrew-core
|
||||
[8]: https://formulae.brew.sh/formula/
|
||||
[9]: https://opensource.com/article/20/3/github-hub
|
||||
[10]: https://github.com/tldr-pages/tldr
|
||||
[11]: https://discourse.brew.sh/t/add-linux-support-to-existing-cask/5766
|
||||
[12]: https://docs.brew.sh/How-to-Create-and-Maintain-a-Tap
|
||||
[13]: https://opensource.com/article/19/3/move-your-dotfiles-version-control
|
Loading…
Reference in New Issue
Block a user