Linux也能用Homebrew?

1,952 阅读2分钟

为什么要在Linux下使用Homebrew    

    对于很多开发者来说,MacOS 的开发环境仍然是首选,不仅仅是因为苹果硬件的极致体验,还有 MacOS 的大量优质软件让开发者爱不释手。 

    比如 Homebrew + Oh My ZSH! + iTerm2 的搭档简直是绝配。但是如果没有苹果的硬件和系统又如何优化开发体验呢? 

    之前的文章中我们总结了 Ubuntu 打造成生产力工具的方法和推荐了一个优秀的终端工具 TerminatorLinux 是能够使用 Oh My ZSH!的,并且每个Liunx发行版都有自己默认的包管理器或软件商店,但是比如 apt  yum snap 可能软件包更新不够快不够多,我们就可以尝试Homebrew了。

     对于 Homebrew

  • 安装在用户 home 目录下,不需要 sudo
  • 安装默认包管理器未分发的软件
  • 安装最新的软件包
  • MacOS / Linux / Windows  系统取得一致的包管理体验(windows 指 Windows Subsystem for Linux (WSL)

安装 

安装前检查

  • 64-bit x86_64 CPU  (对于 ARM 和 32-bit x86 的安装可参考官方文档 )
  • GCC 4.7.0 or newer 
  • Linux 2.6.32 or newer 
  • Glibc 2.13 or newer 

硬件满足的情况下可以使用以下命令安装依赖

Debian or Ubuntu

sudo apt-get install build-essential curl file git

Fedora, CentOS, or Red Hat

sudo yum groupinstall 'Development Tools'
sudo yum install curl file git
sudo yum install libxcrypt-compat # needed by Fedora 30 and up

第一步

sh -c "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh)" 

执行完该步骤,要等上半小时左右才能安装完毕。过程如下


第二步

新增如下代码到 /etc/profile  或 $HOME/.profile 添加可执行文件到环境变量

export PATH="/home/linuxbrew/.linuxbrew/bin:$PATH"

效果

brew -v
Homebrew 2.2.1 
Homebrew/linuxbrew-core (git revision 8677; last commit 2019-12-13)

使用

用法和 MacOS 是一样的,快使用 brew install hello 来体验吧!

优化

Homebrew 国内镜像

阿里云镜像

 cd "$(brew --repo)"  

git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git  

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" 

git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git  

brew update

清华镜像

git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git

git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git

git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git

brew update

复原

git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git

git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git

git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask.git

brew update

参考