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

HTML Tutorial: Collection of commonly used HTML tags (5)

These introduced HTML tags do not necessarily ful...

Three ways to implement text color gradient in CSS

In the process of web front-end development, UI d...

Analyze the selection problem of storing time and date types in MySQL

In general applications, we use timestamp, dateti...

Detailed process record of nginx installation and configuration

Table of contents 1 Introduction to nginx 1 What ...

Nodejs module system source code analysis

Table of contents Overview CommonJS Specification...

Detailed explanation of Vue's caching method example

Recently, a new requirement "front-end cache...

CSS3 creates web animation to achieve bouncing ball effect

Basic preparation For this implementation, we nee...

Docker implements container port binding local port

Today, I encountered a small problem that after s...

Solution to the MySQL error "Every derived table must have its own alias"

MySQL reports an error when executing multi-table...

Node.js makes a simple crawler case tutorial

Preparation First, you need to download nodejs, w...

Tutorial on configuring and using i3 window manager in Linux

In this article, I will show you how to install a...

B2C website user experience detail design reference

Recently, when using Apple.com/Ebay.com/Amazon.co...

Implementing file content deduplication and intersection and difference in Linux

1. Data Deduplication In daily work, there may be...