zl程序教程

您现在的位置是:首页 >  其他

当前栏目

Mac系统下Homebrew以及Telnet的安装与使用说明

安装系统Mac 以及 说明 telnet Homebrew 使用
2023-09-11 14:17:06 时间

小编的系统是MacOS  Catalina10.15.4,由于新版本的macos 取消了内置的telnet命令,所以要使用telnet命令的话,需要大家手动安装。下面介绍一下如何安装:

  • 首先安装Homebrew

  • 通过brew命令来安装Telnet

一、安装 Homebrew

1、打开官网:The Missing Package Manager for macOS (or Linux) — Homebrew,复制安装命令

安装命令如下:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

2、复制命令到终端,按回车执行,如下图所示:

3、按任意键,输入密码,开始下载安装

网络慢的同学请耐心等待那么几分钟...

4、查看homebrew 是否安装成功

也可以用brew -v来查看

zhengxiaofang@zhengxiaofangdeMacBook-Pro ~ % brew -v
Homebrew 2.4.10
Homebrew/homebrew-core N/A
zhengxiaofang@zhengxiaofangdeMacBook-Pro ~ %

到这一步表示home brew安装成功

《------【说明:如果安装Homebrew遇到以下报错】------》

问题:curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused

原因:由于某些因素,导致GitHub的raw.githubusercontent.com域名解析被污染了

解决办法:通过修改hosts解决此问题,按以下步骤操作可解决该问题

(1)查询raw.githubusercontent.com的真实IP

The Best IP Address, Email and Networking Tools - IPAddress.com查询

(2)修改hosts

sudo vim /etc/hosts

(3)添加如下内容:

199.232.28.133 raw.githubusercontent.com

《------【修改完hosts,再次执行Homebrew 安装步骤即可】------》

二、安装Telnet(使用 Homebrew 安装Telnet)

1、命令安装

brew install telnet

如果安装过程遇到跟小编一样的错误

报错1:

error: RPC failed; curl 18 transfer closed with outstanding read data remaining

fatal: The remote end hung up unexpectedly

fatal: early EOF

fatal: index-pack failed

出现以上错误有以下原因

(1)缓存区溢出curl的postBuffer的默认值太小,需要增加缓存

使用git命令增大缓存(单位是b,524288000B也就500M左右)

git config --global http.postBuffer 524288000

使用git config --list查看是否生效

zhengxiaofang@zhengxiangdeMBP ~ % git config --list  
credential.helper=osxkeychain
zhengxiaofang@zhengxiangdeMBP ~ % git config --global http.postBuffer 524288000
zhengxiaofang@zhengxiangdeMBP ~ % git config --list                            
credential.helper=osxkeychain
http.postbuffer=524288000

(2)网络下载速度缓慢,修改下载速度

git config --global http.lowSpeedLimit 0
git config --global http.lowSpeedTime 999999

报错2:

==> Tapping homebrew/core
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
fatal: unable to access 'https://github.com/Homebrew/homebrew-core/': LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 60

(1)执行下面这句命令,更换为中科院的镜像:

git clone git://mirrors.ustc.edu.cn/homebrew-core.git/ /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1

(2)把homebrew-core的镜像地址也设为中科院的国内镜像,进入路径:/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core,执行:

git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git

(3)检查是否可以更新成功,问题解决过程如下:

zhengxiaofang@zhengxiangdeMBP ~ % brew install telnet
Updating Homebrew...
==> Tapping homebrew/core
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (5/5), done.
error: RPC failed; curl 18 transfer closed with outstanding read data remaining
fatal: the remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed
Error: Failure while executing; `git clone https://github.com/Homebrew/homebrew-core /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core` exited with 128.
Error: Failure while executing; `/usr/local/bin/brew tap homebrew/core` exited with 1.
==> Tapping homebrew/core
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
fatal: unable to access 'https://github.com/Homebrew/homebrew-core/': LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 60
Error: Failure while executing; `git clone https://github.com/Homebrew/homebrew-core /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core` exited with 128.
Error: Failure while executing; `/usr/local/bin/brew tap homebrew/core` exited with 1.
zhengxiaofang@zhengxiangdeMBP ~ % git clone git://mirrors.ustc.edu.cn/homebrew-core.git/ /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
remote: Enumerating objects: 5418, done.
remote: Counting objects: 100% (5418/5418), done.
remote: Compressing objects: 100% (5199/5199), done.
remote: Total 5418 (delta 53), reused 764 (delta 10)
Receiving objects: 100% (5418/5418), 4.48 MiB | 92.00 KiB/s, done.
Resolving deltas: 100% (53/53), done.
zhengxiaofang@zhengxiangdeMBP ~ % 
zhengxiaofang@zhengxiangdeMBP homebrew-core % git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
zhengxiaofang@zhengxiangdeMBP homebrew-core % git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
zhengxiaofang@zhengxiangdeMBP homebrew-core % brew update
Already up-to-date.

(4)更新成功,可返回第1步,执行

brew install telnet

发现又报错!!小编要哭了,不行不行,忍住,继续百度,总有办法解决!

zhengxiaofang@zhengxiangdeMBP homebrew-core % brew install telnet
Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/telnet-63.catalina.bottle.tar.gz
######################################################################## 100.0%
Error: No such file or directory @ dir_chdir - /usr/local/Cellar
Warning: Bottle installation failed: building from source.
telnet: A full installation of Xcode.app is required to compile
this software. Installing just the Command Line Tools is not sufficient.

Xcode can be installed from the App Store.
Error: An unsatisfied requirement failed this build.

由于登陆用户不是HomeBrew的安装用户所以报以上错误

解决如下:

在当前用户重新安装HomeBrew

zhengxiaofang@zhengxiangdeMBP ~ % /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Password:
==> This script will install:
/usr/local/bin/brew
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
/usr/local/Homebrew
==> The following new directories will be created:
/usr/local/Cellar

Press RETURN to continue or any other key to abort
==> /usr/bin/sudo /bin/mkdir -p /usr/local/Cellar
==> /usr/bin/sudo /bin/chmod g+rwx /usr/local/Cellar
==> /usr/bin/sudo /usr/sbin/chown zhengxiaofang /usr/local/Cellar
==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/Cellar
==> Downloading and installing Homebrew...
remote: Enumerating objects: 8, done.
remote: Counting objects: 100% (8/8), done.
remote: Total 10 (delta 8), reused 8 (delta 8), pack-reused 2
Unpacking objects: 100% (10/10), done.
From https://github.com/Homebrew/brew
 * [new branch]          dependabot/bundler/Library/Homebrew/sorbet-0.5.5868 -> origin/dependabot/bundler/Library/Homebrew/sorbet-0.5.5868
 * [new branch]          dependabot/bundler/Library/Homebrew/sorbet-runtime-0.5.5868 -> origin/dependabot/bundler/Library/Homebrew/sorbet-runtime-0.5.5868
HEAD is now at 3b2a9c3b5 Merge pull request #8335 from waldyrious/show-cask-descs-in-info-command
Already up-to-date.
==> Installation successful!

==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
Read the analytics documentation (and how to opt-out) here:
  https://docs.brew.sh/Analytics
No analytics data has been sent yet (or will be during this `install` run).

==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
  https://github.com/Homebrew/brew#donations

==> Next steps:
- Run `brew help` to get started
- Further documentation:
    https://docs.brew.sh
zhengxiaofang@zhengxiangdeMBP ~ %

再次尝试安装telnet,终于没报错了!!!看样子是成功了。。。赶紧敲下telnet命令看看

zhengxiaofang@zhengxiangdeMBP ~ % brew install telnet
Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/telnet-63.catalina.bottle.tar.gz
Already downloaded: /Users/zhengxiaofang/Library/Caches/Homebrew/downloads/ee514a77919208ba9448ee657c9ea26d19d999b7162940f3909c35f128a43e34--telnet-63.catalina.bottle.tar.gz
==> Pouring telnet-63.catalina.bottle.tar.gz
🍺  /usr/local/Cellar/telnet/63: 4 files, 138.1KB
zhengxiaofang@zhengxiangdeMBP ~ %

2、查看是否安装成功

zhengxiaofang@zhengxiangdeMBP ~ % telnet
telnet> telnet www.baidu.com 80
Trying 14.215.177.38...
Connected to www.a.shifen.com.
Escape character is '^]'.

HTTP/1.1 400 Bad Request

Connection closed by foreign host.
zhengxiaofang@zhengxiangdeMBP ~ %
zhengxiaofang@zhengxiangdeMBP ~ %

到这一步表示telnet安装成功,就可以开始使用telnet命令了。你安装成功了吗???

【总结】

附 Homebrew常用操作:

  • brew install xxx           安装xxx
  • brew uninstall xxx       卸载xxx
  • brew update  xxx         更新xxx
  • brew doctor                 修复brew
  • brew list           列出已安装的软件
  • brew home      用浏览器打开brew的官方网站
  • brew info         显示软件信息
  • brew deps       显示包依赖

当我们在mac下使用brew安装软件时,默认每次都会自动更新homebrew,显示
Updating Homebrew...,网络状况不好或者没有换源的时候,很慢,会卡在这里许久不动。
我们可以关闭自动更新,在命令行执行:

export HOMEBREW_NO_AUTO_UPDATE=true

即可关闭自动更新。

如果想要重启后设置依然生效,可以把上面这行加入到当前正在使用的shell的配置文件中,比如我正在使用的是zsh,那么执行以下语句:

vi ~/.zshrc

然后在合适的位置,加入上面那一行配置。

小编在使用telnet时,随手做个记录,希望对大家有所帮助。

有帮助,点个赞。要细品,可收藏。要继续,请关注。如成功,请分享。有疑问,请留评。