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

This article takes you into the world of js data types and data structures

Table of contents 1. What is dynamic typing? 2. D...

Analysis of the principle of Vue nextTick

Table of contents Event Loop miscroTask (microtas...

Mysql master-slave synchronization configuration scheme under Centos7 system

Preface Recently, when working on a high-availabi...

Summary of the main attributes of the body tag

bgcolor="text color" background="ba...

Detailed explanation of MySQL DEFINER usage

Table of contents Preface: 1.Brief introduction t...

VMware, nmap, burpsuite installation tutorial

Table of contents VMware BurpSuite 1. Virtual mac...

How to install docker and portainer in kali

With the emergence of docker, many services have ...

Specific method to delete mysql service

MySQL prompts the following error I went to "...

Mysql Chinese sorting rules description

When using MySQL, we often sort and query a field...

Complete step-by-step record of MySQL 8.0.26 installation and uninstallation

Table of contents Preface 1. Installation 1. Down...

js to achieve a simple lottery function

This article shares the specific code of js to im...

Docker implements container port binding local port

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

Win10 + Ubuntu 16.04 dual system perfect installation tutorial [detailed]

Be sure to remember to back up your data, it is p...

How to add java startup command to tomcat service

My first server program I'm currently learnin...

Vue implements countdown function

This article example shares the specific code of ...