Mac下 使用 HomeBrew 管理第三方软件包, 与哪些好用的第三方软件包

时间:2024-04-15 22:10:32

什么是HomeBrew

使用Homebrew安装 Apple(或您的 Linux 系统)没有预装但 你需要的东西

安装HomeBrew

1.1将brew的install文件下载本地

cd ~ && curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install >> brew_install

1.2修改install文件的镜像源

# BREW_REPO = "https://github.com/Homebrew/brew".freeze
BREW_REPO = "git://mirrors.ustc.edu.cn/brew.git".freeze

1.3安装brew

/usr/bin/ruby ~/brew_install

 1.4验证是否安装成功

$ brew doctor

如果没成功先卸载brew一下,再试

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
 

如何使用 HomeBrew 安装软件

安装完 HomeBrew 后可使用以下命令进行软件包安装:

brew install 软件名称

HomeBrew 常用命令

$ brew --help    # 查看简洁帮助
$ man brew     # 完整命令帮助
$ brew install [name]    # 安装软件包
$ brew uninstall [name]    # 卸载软件包
$ brew search [name]    # 搜索软件包
$ brew list    # 显示已经安装的所有软件包
$ brew update    # 同步远程最新更新情况,对本机已经安装并有更新的软件用*标明
$ brew outdated    # 查看已安装的哪些软件包需要更新
$ brew upgrade [name]    # 更新单个软件包
$ brew info [name]    # 查看软件包信息
$ brew home [name]    # 访问软件包官方站
$ brew cleanup    # 清理所有已安装软件包的历史老版本
$ brew cleanup [name]    # 清理单个已安装软件包的历史版本

 

HomeBrew中安装的好用的三方软件

wget

1、安装wget

安装命令:brew install wget

检验是否安装成功:

wget http://www.arefly.com/

安装成功后结果如下:

MacBook-Pro:~ home$ wget http://www.arefly.com/
--2020-06-02 14:46:12--  http://www.arefly.com/
正在解析主机 www.arefly.com (www.arefly.com)... 115.29.198.97
正在连接 www.arefly.com (www.arefly.com)|115.29.198.97|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 301 Moved Permanently
位置:https://www.arefly.com/ [跟随至新的 URL]
--2020-06-02 14:46:12--  https://www.arefly.com/
正在连接 www.arefly.com (www.arefly.com)|115.29.198.97|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:75961 (74K) [text/html]
正在保存至: “index.html”

index.html          100%[===================>]  74.18K  --.-KB/s  用时 0.01s   

2020-06-02 14:46:13 (5.38 MB/s) - 已保存 “index.html” [75961/75961])

 

Zsh 入门(安装及使用)

先看下你的 CentOS 支持哪些 shell:cat /etc/shells,正常结果应该是这样的:

MacBook-Pro:~ dunk$ cat /etc/shells
# List of acceptable shells for chpass(1).
# Ftpd will not allow users to connect who are not using
# one of these shells.

/bin/bash
/bin/csh
/bin/dash
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh

默认 CentOS / Ubuntu / Mac 系统用的是 Bash,倒也不是说 Bash 不好,而是说我们有更好的选择。

Zsh 安装

  • CentOS 安装:sudo yum install -y zsh
  • Ubuntu 安装:sudo apt-get install -y zsh
  • 在检查下系统的 shell:cat /etc/shells,你会发现多了一个:/bin/zsh

使用 Zsh 扩展集合:oh-my-zsh

什么是Oh My Zsh

Oh My Zsh是一款社区驱动的命令行工具,正如它的主页上说的,Oh My Zsh 是一种生活方式。它基于zsh命令行,提供了主题配置,插件机制,已经内置的便捷操作。给我们一种全新的方式使用命令行。

Oh My Zsh这个名字听起来就很有意思,它是基于zsh命令行的一个扩展工具集,提供了丰富的扩展功能。

Oh My Zsh只是一个对zsh命令行环境的配置包装框架,但它不提供命令行窗口,更不是一个独立的APP。

  • oh-my-zsh 帮我们整理了一些常用的 Zsh 扩展功能和主题:https://github.com/robbyrussell/oh-my-zsh
  • 我们无需自己去捣搞 Zsh,直接用 oh-my-zsh 就足够了,如果你想继续深造的话那再去弄。
  • 先安装 git:sudo yum install -y git
  • 安装 oh-my-zsh
  • Basic Installation
    
    Oh My Zsh is installed by running one of the following commands in your terminal. You can install this via the command-line with either curl or wget.
    
    via curl
    
    sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
    via wget
    // 这里使用
    wget
    sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

     

  • 在以 root 用户为前提下,oh-my-zsh 的安装目录:/root/.oh-my-zsh
  • 在以 root 用户为前提下,Zsh 的配置文件位置:/root/.zshrc
  • 为 root 用户设置 zsh 为系统默认 shell:chsh -s /bin/zsh root  注意:这里安装的时候会有

    Do you want to change your default shell to zsh? [Y/n] 的选择,写Y然后回车就可以

  • 如果你要重新恢复到 bash:chsh -s /bin/bash root
  • 现在你关掉终端或是重新连上 shell,现在开头是一个箭头了,如下图:

 

  • Oh My Zsh目录结构

    进入~/.oh-my-zsh目录后,看看该目录的结构

lib 提供了核心功能的脚本库
tools 提供安装、升级等功能的快捷工具
plugins 自带插件的存在放位置
templates 自带模板的存在放位置
themes  自带主题文件的存在放位置
custom 个性化配置目录,自安装的插件和主题可放这里

Zsh 配置

插件

  • 启用 oh-my-zsh 中自带的插件。
  • oh-my-zsh 的插件列表介绍(太长了,用源码不精准地统计下有 149 个):https://github.com/robbyrussell/oh-my-zsh/wiki/Plugins
  • 编辑配置文件:vim /root/.zshrc,找到下图的地方,怎么安装,原作者注释写得很清楚了,别装太多了,默认 git 是安装的

git 自动显示当前分支名称和修改状态

git 快捷键

https://github.com/ohmyzsh/ohmyzsh/blob/master/plugins/git/git.plugin.zsh
zsh帮我们配置了一些git的常常用命令简写,我常用的是几个命令

gst 代表 git status
# 添加当前目录的所有文件到暂存区 alias ga . =\'git add .\'
# 提交暂存区到仓库区  alias gcmsg =\'git commit -m\'
# 提交工作区自上次commit之后的变化,直接到仓库区 gca 代表 git commit -v -a\'
# 提交  alias gp =\'git push\'

# 切换到指定分支,并更新工作区 gco 代表 git checkout
# 列出所有本地分支 alias gb =\'git branch\'
# 列出所有本地分支和远程分支 alias gba =\'git branch -a\'
 

 进入 ~/.zshrc配置文件,先给看下我的配置,可以凭自己喜好更改:

  vim ~/.zshrc

# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH

# Path to your oh-my-zsh installation.
export ZSH="/Users/dunkhome/.oh-my-zsh"

# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="robbyrussell"

# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in $ZSH/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )

# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"
# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"

# Uncomment the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true"

# Uncomment the following line to automatically update without prompting.
# DISABLE_UPDATE_PROMPT="true"

# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13

# Uncomment the following line if pasting URLs and other text is messed up.
# DISABLE_MAGIC_FUNCTIONS=true

# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"
# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"

# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"

# Uncomment the following line to display red dots whilst waiting for completion.
# COMPLETION_WAITING_DOTS="true"

# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"

# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see \'man strftime\' for details.
# HIST_STAMPS="mm/dd/yyyy"

# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder

# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(git)

source $ZSH/oh-my-zsh.sh

# User configuration

# export MANPATH="/usr/local/man:$MANPATH"

# You may need to manually set your language environment
# export LANG=en_US.UTF-8

# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
#   export EDITOR=\'vim\'
# else
#   export EDITOR=\'mvim\'
# fi

# Compilation flags
# export ARCHFLAGS="-arch x86_64"

# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#

 

设置主题

我们默认使用的主题叫做robbyrussel

Oh My Zsh默认自带了一些默认主题,存放在~/.oh-my-zsh/themes目录中。我们可以查看这些主题

➜  ~ git:(master) ✗ ls ~/.oh-my-zsh
CODE_OF_CONDUCT.md cache              oh-my-zsh.sh       tools
CONTRIBUTING.md    custom             plugins
LICENSE.txt        lib                templates
README.md          log                themes
➜  ~ git:(master) ✗ ls ~/.oh-my-zsh/themes
3den.zsh-theme                 kardan.zsh-theme
Soliah.zsh-theme               kennethreitz.zsh-theme
adben.zsh-theme                kiwi.zsh-theme
af-magic.zsh-theme             kolo.zsh-theme
afowler.zsh-theme              kphoen.zsh-theme
agnoster.zsh-theme             lambda.zsh-theme
alanpeabody.zsh-theme          linuxonly.zsh-theme
amuse.zsh-theme                lukerandall.zsh-theme
apple.zsh-theme                macovsky-ruby.zsh-theme
arrow.zsh-theme                macovsky.zsh-theme
aussiegeek.zsh-theme           maran.zsh-theme
avit.zsh-theme                 mgutz.zsh-theme
awesomepanda.zsh-theme         mh.zsh-theme
bira.zsh-theme                 michelebologna.zsh-theme
blinks.zsh-theme               mikeh.zsh-theme
bureau.zsh-theme               miloshadzic.zsh-theme
candy-kingdom.zsh-theme        minimal.zsh-theme
candy.zsh-theme                mira.zsh-theme
clean.zsh-theme                mortalscumbag.zsh-theme
cloud.zsh-theme                mrtazz.zsh-theme
crcandy.zsh-theme              murilasso.zsh-theme
crunch.zsh-theme               muse.zsh-theme
cypher.zsh-theme               nanotech.zsh-theme
dallas.zsh-theme               nebirhos.zsh-theme
darkblood.zsh-theme            nicoulaj.zsh-theme
daveverwer.zsh-theme           norm.zsh-theme
dieter.zsh-theme               obraun.zsh-theme
dogenpunk.zsh-theme            peepcode.zsh-theme
dpoggi.zsh-theme               philips.zsh-theme
dst.zsh-theme                  pmcgee.zsh-theme
dstufft.zsh-theme              pygmalion-virtualenv.zsh-theme
duellj.zsh-theme               pygmalion.zsh-theme
eastwood.zsh-theme             random.zsh-theme
edvardm.zsh-theme              re5et.zsh-theme
emotty.zsh-theme               refined.zsh-theme
essembeh.zsh-theme             rgm.zsh-theme
evan.zsh-theme                 risto.zsh-theme
fino-time.zsh-theme            rixius.zsh-theme
fino.zsh-theme                 rkj-repos.zsh-theme
fishy.zsh-theme                rkj.zsh-theme
flazz.zsh-theme                robbyrussell.zsh-theme
fletcherm.zsh-theme            sammy.zsh-theme
fox.zsh-theme                  simonoff.zsh-theme
frisk.zsh-theme                simple.zsh-theme
frontcube.zsh-theme            skaro.zsh-theme
funky.zsh-theme                smt.zsh-theme
fwalch.zsh-theme               sonicradish.zsh-theme
gallifrey.zsh-theme            sorin.zsh-theme
gallois.zsh-theme              sporty_256.zsh-theme
garyblessington.zsh-theme      steeef.zsh-theme
gentoo.zsh-theme               strug.zsh-theme
geoffgarside.zsh-theme         sunaku.zsh-theme
gianu.zsh-theme                sunrise.zsh-theme
gnzh.zsh-theme                 superjarin.zsh-theme
gozilla.zsh-theme              suvash.zsh-theme
half-life.zsh-theme            takashiyoshida.zsh-theme
humza.zsh-theme                terminalparty.zsh-theme
imajes.zsh-theme               theunraveler.zsh-theme
intheloop.zsh-theme            tjkirch.zsh-theme
itchy.zsh-theme                tjkirch_mod.zsh-theme
jaischeema.zsh-theme           tonotdo.zsh-theme
jbergantine.zsh-theme          trapd00r.zsh-theme
jispwoso.zsh-theme             wedisagree.zsh-theme
jnrowe.zsh-theme               wezm+.zsh-theme
jonathan.zsh-theme             wezm.zsh-theme
josh.zsh-theme                 wuffers.zsh-theme
jreese.zsh-theme               xiong-chiamiov-plus.zsh-theme
jtriley.zsh-theme              xiong-chiamiov.zsh-theme
juanghurtado.zsh-theme         ys.zsh-theme
junkfood.zsh-theme             zhann.zsh-theme
kafeitu.zsh-theme
➜  ~ git:(master) ✗ 

默认插件

Oh My Zsh 默认自带了一些默认插件,存放在~/.oh-my-zsh/plugins目录中。我们可以查看这些插件

➜  ~ git:(master) ✗ ls ~/.oh-my-zsh/plugins
adb                      git-extras               profiles
alias-finder             git-flow                 pyenv
ansible                  git-flow-avh             pylint
ant                      git-hubflow              python
apache2-macports         git-prompt               rails
arcanist                 gitfast                  rake
archlinux                github                   rake-fast
asdf                     gitignore                rand-quote
autoenv                  glassfish                rbenv
autojump                 globalias                rbfu
autopep8                 gnu-utils                react-native
aws                      go                       rebar
battery                  golang                   redis-cli
bazel                    gpg-agent                repo
bbedit                   gradle                   ripgrep
bgnotify                 grails                   ros
boot2docker              grunt                    rsync
bower                    gulp                     ruby
branch                   hanami                   rust
brew                     helm                     rustup
bundler                  heroku                   rvm
cabal                    history                  safe-paste
cake                     history-substring-search salt
cakephp3                 hitokoto                 sbt
capistrano               homestead                scala
cargo                    httpie                   scd
cask                     ionic                    screen
catimg                   iterm2                   scw
celery                   jake-node                sdk
chruby                   jenv                     sfdx
chucknorris              jfrog                    sfffe
cloudapp                 jhbuild                  shell-proxy
cloudfoundry             jira                     shrink-path
codeclimate              jruby                    singlechar
coffee                   jsontools                spring
colemak                  jump                     sprunge
colored-man-pages        kate                     ssh-agent
colorize                 keychain                 stack
command-not-found        kitchen                  sublime
common-aliases           knife                    sudo
compleat                 knife_ssh                supervisor
composer                 kops                     suse
copybuffer               kube-ps1                 svcat
copydir                  kubectl                  svn
copyfile                 laravel                  svn-fast-info
cp                       laravel4                 swiftpm
cpanm                    laravel5                 symfony
dash                     last-working-dir         symfony2
debian                   lein                     systemadmin
dircycle                 lighthouse               systemd
direnv                   lol                      taskwarrior
dirhistory               lxd                      terminitor
dirpersist               macports                 terraform
django                   magic-enter              textastic
dnf                      man                      textmate
dnote                    marked2                  thefuck
docker                   mercurial                themes
docker-compose           meteor                   thor
docker-machine           microk8s                 tig
doctl                    minikube                 timer
dotenv                   mix                      tmux
dotnet                   mix-fast                 tmux-cssh
droplr                   mosh                     tmuxinator
drush                    mvn                      torrent
eecms                    mysql-macports           transfer
emacs                    n98-magerun              tugboat
ember-cli                nanoc                    ubuntu
emoji                    ng                       ufw
emoji-clock              nmap                     urltools
emotty                   node                     vagrant
encode64                 nomad                    vagrant-prompt
extract                  npm                      vault
fabric                   npx                      vi-mode
fancy-ctrl-z             nvm                      vim-interaction
fasd                     oc                       virtualenv
fastfile                 osx                      virtualenvwrapper
fbterm                   otp                      vscode
fd                       pass                     vundle
fedora                   paver                    wakeonlan
firewalld                pep8                     wd
flutter                  per-directory-history    web-search
forklift                 percol                   wp-cli
fossil                   perl                     xcode
frontend-search          perms                    yarn
fzf                      phing                    yii
gas                      pip                      yii2
gatsby                   pipenv                   yum
gb                       pj                       z
gcloud                   please                   zeus
geeknote                 pod                      zsh-interactive-cd
gem                      postgres                 zsh-navigation-tools
git                      pow                      zsh_reload
git-auto-fetch           powder
git-escape-magic         powify
➜  ~ git:(master) ✗ 

 

默认是只有git

plugins=(git)

 

新增插件举例 

  • 安装zsh-syntax-highlighting语法高亮插件

下载插件

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git
echo "source ${(q-)PWD}/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ${ZDOTDIR:-$HOME}/.zshrc
 
编辑激活 ~/.zshrc配置文件
 
plugins=(git zsh-syntax-highlighting )
 
保存后 source一下,让改变生效
 
source ~/.zshrc
 
发现再敲命令就有颜色了,比如命令有误的时候是红色,命令正确的时候是绿色。
 
 

软件安装位置:cd ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions

 

oh my zsh 手动更新,可以执行

upgrade_oh_my_zsh

卸载oh my zsh

直接在终端中,运行uninstall_oh_my_zsh既可以卸载。

备注:

 插件可以装很多,但是装多了之后会在每次进入命令提示符的时候明显变慢。慎用。