The correct way to use Homebrew in Linux

The correct way to use Homebrew in Linux

Many people use Linux Homebrew. Here are three tips to help you use it better:

Avoid environmental pollution

First, avoid adding Homebrew's bin directory to $PATH , and only soft-link the executables you need to ~/bin (which is in $PATH ) to avoid environmental pollution.

When you compile or install new software, you obviously want it to rely on system files under the /usr directory. If you put Homebrew's bin directory in $PATH for a long time, then gcc/clang in Homebrew will be called during compilation (these two are often automatically installed in brew, used to compile and install source code packages in homebrew). Even if your brew does not have gcc/clang, it will call pkg-config/python and other brew software when analyzing dependencies, thereby returning dependencies based on homebrew, which is obviously not what you want.

So just make a soft link to the tools you need and put them under ~/bin so that you can use homebrew and avoid environmental pollution. You just need to temporarily add homebrew's bin directory to $PATH when calling brew to install a new package, and cancel it when you are done. We use two functions to do this:

function brew_disable() {
 export PATH=${PATH##*"/.linuxbrew/bin:"}
 export PATH=${PATH##*"/.linuxbrew/sbin:"}
 export MANPATH=${MANPATH##*"/.linuxbrew/share/man:"}
 export INFOPATH=${INFOPATH##*"/.linuxbrew/share/info:"}
}

function brew_enable() {
 BREW='/home/linuxbrew/.linuxbrew'
 brew_disable
 export PATH="$BREW/bin:$BREW/sbin:$PATH"
 export MANPATH="$BREW/share/man:$MANPATH"
 export INFOPATH="$BREW/share/info:$INFOPATH"
 export HOMEBREW_NO_AUTO_UPDATE=1
}

Put the above two functions in your bashrc. You don't need to enable homebrew at ordinary times. Call brew_enable when you need to install it, and use brew_disable after the package is installed.

There is another way to do it, just write a function named brew:

function brew() {
  PATH="/home/linuxbrew/.linuxbrew/bin:$PATH" /home/linuxbrew/.linuxbrew/bin/brew "$@"
}

Then when you type the brew command, the path will be temporarily set and the real brew executable will be called:

brew install fzf

With the above function, you don't need to set any brew path and can install the software directly. If you don't want to overwrite the name brew, you can rename the above function to brew2 or something like that.

Disable automatic updates

The second optimization is to disable automatic brew updates every time:

export HOMEBREW_NO_AUTO_UPDATE=1

This can prevent you from having to spend half a day updating the software every time you install it and need to use it urgently. This is very frustrating. With this macro, you can manually brew update regularly.

Use a temporary agent

Continue to add a line in bashrc:

alias socks5="http_proxy=socks5://127.0.0.1:1080 https_proxy=socks5://127.0.0.1:1080 all_proxy=socks5://127.0.0.1:1080 "

Note that there is a space before the last quotation mark, so if you want brew to go through the proxy, you can do:

socks5 brew install micro

This will not destroy the environment variables, and temporarily set up a socks5 proxy of localhost:1080 for brew to install new software.

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM.

<<:  How to calculate the frame rate FPS of web animations

>>:  How to use binlog for data recovery in MySQL

Recommend

Analysis and solution of MySQL connection throwing Authentication Failed error

[Problem description] On the application side, th...

Perfect solution for theme switching based on Css Variable (recommended)

When receiving this requirement, Baidu found many...

How to calculate the value of ken_len in MySQL query plan

The meaning of key_len In MySQL, you can use expl...

Nginx reverse proxy to go-fastdfs case explanation

background go-fastdfs is a distributed file syste...

Lambda expression principles and examples

Lambda Expressions Lambda expressions, also known...

vue+echarts realizes the flow effect of China map (detailed steps)

@vue+echarts realizes the flow effect of China ma...

CSS scroll-snap scroll event stop and element position detection implementation

1. Scroll Snap is a must-have skill for front-end...

How to explain TypeScript generics in a simple way

Table of contents Overview What are Generics Buil...

Detailed explanation of the solution to Ubuntu dual system stuck when starting

Solution to Ubuntu dual system stuck when startin...

Two common solutions to html text overflow display ellipsis characters

Method 1: Use CSS overflow omission to solve The ...

Notes on matching MySql 8.0 and corresponding driver packages

MySql 8.0 corresponding driver package matching A...

Detailed tutorial on installing mysql on centos 6.9

1. Confirm whether MySQL has been installed. You ...

Solution to the problem of web page flash animation not displaying

<br />The solution steps are as follows: Sta...

Problems and solutions encountered when installing mininet on Ubuntu 16.04.4LTS

Mininet Mininet is a lightweight software defined...