coder| 折騰回 win 開發環境之 linuxbrew

date: 2020-7-6 23:02:03
title: coder| 折騰回 win 開發環境之 linuxbrew

是否推薦 linuxbrew: 不推薦

內容簡介:

  • why: 爲什麼嘗試 linuxbrew
  • how: 如何使用
  • WTF: 踩到了哪些坑
  • mark: 總結

why: 爲什麼嘗試 linuxbrew

  • homebrew 官網推薦
  • 剛從 mac 切換過來, 還是想使用熟悉的工具
  • 由於國內感人的網速, 我手裏積累不少常用的鏡像源, 平時在使用 homebrew 的過程中, 也稍微接觸過 linuxbrew, 有點印象

how: 如何使用

目前可用的 linuxbrew 源:

清華大學開源軟件鏡像站 - linuxbrew: https://mirror.tuna.tsinghua.edu.cn/help/linuxbrew-bottles/

參考 homebrew 官網和鏡像站提供的幫助文檔, 就可以安裝上 linuxbrew

  • 安裝
# 1. 安裝 ruby
sudo apt install -y ruby

# 2. 獲取 homebrew 安裝腳本
# 官網提供的腳本
# /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
mkdir tmp
cd tmp
wget https://raw.githubusercontent.com/Homebrew/install/master/install.sh

# 3. 使用鏡像源加速安裝 linuxbrew
sed -i 's/https://github.com/Homebrew/brew/https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git/g' install.sh
bash install.sh
# 執行到 “==> Tapping homebrew/core” 時 Ctrl-C
export PATH=/home/linuxbrew/.linuxbrew/Homebrew/bin:$PATH # 將 brew 添加到 PATH
git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/linuxbrew-core.git "$(brew --repo homebrew/core)"
# 再次執行 install
bash install.sh
  • brew 簡單使用
brew search xxx # 查找
brew info xxx # 查看軟件包的信息
brew install xxx # 安裝
brew install [email protected] # 安裝不同版本

brew info 查看到的信息很有用:

  • 比如軟件的官網
  • 比如需要設置 PATH 等信息

WTF: 踩到了哪些坑

  • 第一個坑是 homebrew 和 linuxbrew 傻傻分不清楚, 是的, 因爲犯了這個 低級錯誤, 安裝使用 linuxbrew 環節浪費了大量的時間
  • 第二個坑是鏡像源並不是完備的, 經常會遇到軟件 failed to download 的情況, 由於還耦合了上面的問題, 這個問題也導致花了大量時間
  • 第三個坑是 linuxbrew 和原生包管理, 在文檔等方面有明顯的劣勢, 遇到問題的 debug 難度以及解決手段自然就少了

最後貼一下 linuxbrew 調教一番 之後的簡單配置:

# 下面使用的 fishshell, 比 bash/zsh 等都好用, 推薦~
# ~/.config/fish/config.fish, 相當於 .bashrc / .zshrc

# 安裝 linuxbrew 後, 設置使用 linuxbrew 生效
set -gx HOMEBREW_PREFIX "/home/linuxbrew/.linuxbrew";
set -gx HOMEBREW_CELLAR "/home/linuxbrew/.linuxbrew/Cellar";
set -gx HOMEBREW_REPOSITORY "/home/linuxbrew/.linuxbrew/Homebrew";
set -q PATH; or set PATH ''; set -gx PATH "/home/linuxbrew/.linuxbrew/bin" "/home/linuxbrew/.linuxbrew/sbin" $PATH;
set -q MANPATH; or set MANPATH ''; set -gx MANPATH "/home/linuxbrew/.linuxbrew/share/man" $MANPATH;
set -q INFOPATH; or set INFOPATH ''; set -gx INFOPATH "/home/linuxbrew/.linuxbrew/share/info" $INFOPATH;

# 下載失敗時, 切換到原生源
function brew_ori
    set -e HOMEBREW_BOTTLE_DOMAIN
    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/linuxbrew-core.git
    brew update
end

# 切換到鏡像源
function brew_thu
    set -gx HOMEBREW_BOTTLE_DOMAIN https://mirrors.tuna.tsinghua.edu.cn/linuxbrew-bottles
    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/linuxbrew-core.git
    brew update
end

# 使用 linuxbrew 安裝的 gcc
set -g LDFLAGS "-L/home/linuxbrew/.linuxbrew/opt/[email protected]/lib"
set -g CPPFLAGS "-I/home/linuxbrew/.linuxbrew/opt/[email protected]/include"

# 安裝 PHP7.2 後, 設置 PATH 生效
# set -g fish_user_paths "/home/linuxbrew/.linuxbrew/opt/[email protected]/bin" $fish_user_paths
# set -g fish_user_paths "/home/linuxbrew/.linuxbrew/opt/[email protected]/sbin" $fish_user_paths

# librdkafka
set -gx LDFLAGS "-L/home/linuxbrew/.linuxbrew/Cellar/librdkafka/1.4.4/lib"
set -gx CPPFLAGS "-I/home/linuxbrew/.linuxbrew/Cellar/librdkafka/1.4.4/include"

mark: 總結

不推薦使用 linuxbrew 替代原生包管理工具

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章