MacOS下使用`HomeBrew`安装`nmap`提示`No such file or directory`失败处理一例

前情

在之前的MBP上是安装过nmap的,也是正常使用的。最近换了新的MBP,系统升级到了macOS Monterey 12.1,之前的数据是用苹果的时间机器迁移过来的;因为机器的CPU从x86架构变成了arm架构,有部分软件不能正常工作,已经陆续做了修复。
今天发现nmap也不能正常使用了,一番小鼓捣修复了,问题的处理很简单,但是在网络上搜索相关错误关键字貌似没有相关的Case,因此还是简单记录一下,方便后面的同学。

此类问题应该是会出现在「之前通过homebrew安装过某些软件」,但是「软件的链接文件失效」的场景。解决方法也是具有一定的通用性的。

以上。

install/reinstall均失败,提示链接文件不存在

➜ /Users/stephen >brew install nmap
Running `brew update --preinstall`...
Error: No such file or directory - /usr/local/var/homebrew/linked/nmap
➜ /Users/stephen >

检查链接文件是存在的

➜ /Users/stephen >ls /usr/local/var/homebrew/linked/nmap
/usr/local/var/homebrew/linked/nmap
➜ /Users/stephen >ll /usr/local/var/homebrew/linked/nmap
lrwxr-xr-x  1 stephen  admin  25 Nov  4  2016 /usr/local/var/homebrew/linked/nmap -> ../../../Cellar/nmap/7.31
➜ /Users/stephen >

debug查看详情,关键的报错信息还是这条文件或目录不存在

➜ /Users/stephen >brew install nmap -debug
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FormulaLoader): loading /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/nmap.rb
Error: Calling brew install --env is disabled! Use `env :std` in specific formula files instead.
/usr/local/Homebrew/Library/Homebrew/cmd/install.rb:143:in `install'
/usr/local/Homebrew/Library/Homebrew/brew.rb:110:in `<main>'
➜ /Users/stephen >brew install nmap --debug
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FormulaLoader): loading /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/nmap.rb
Error: No such file or directory - /usr/local/var/homebrew/linked/nmap
/usr/local/Homebrew/Library/Homebrew/keg.rb:142:in `for'
/usr/local/Homebrew/Library/Homebrew/formula.rb:638:in `linked_version'
/usr/local/Homebrew/Library/Homebrew/install.rb:216:in `install_formula?'
/usr/local/Homebrew/Library/Homebrew/cmd/install.rb:200:in `block in install'
/usr/local/Homebrew/Library/Homebrew/cmd/install.rb:199:in `select'
/usr/local/Homebrew/Library/Homebrew/cmd/install.rb:199:in `install'
/usr/local/Homebrew/Library/Homebrew/brew.rb:110:in `<main>'
➜ /Users/stephen >

确认链接的目标文件是否存在,结果确实不存在

➜ /Users/stephen >ll /usr/local/var/homebrew/linked/nmap
lrwxr-xr-x  1 stephen  admin  25 Nov  4  2016 /usr/local/var/homebrew/linked/nmap -> ../../../Cellar/nmap/7.31
➜ /Users/stephen >
➜ /Users/stephen >cd /usr/local/var/homebrew/linked/
➜ /usr/local/var/homebrew/linked >ls ../../../Cellar/nmap/7.31
ls: ../../../Cellar/nmap/7.31: No such file or directory       
➜ /usr/local/var/homebrew/linked >cd ../../../Cellar/
➜ /usr/local/Cellar >ls | grep nmap
➜ /usr/local/Cellar >ls | grep -i nmap

删除链接文件,重新brew install,OK

➜ /usr/local/Cellar >rm -f /usr/local/var/homebrew/linked/nmap
➜ /usr/local/Cellar >
➜ /usr/local/Cellar >brew install nmap
==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/bottles/nmap-7.92.monterey.bottle.tar.gz
######################################################################## 100.0%
==> Pouring nmap-7.92.monterey.bottle.tar.gz
🍺  /usr/local/Cellar/nmap/7.92: 829 files, 26.7MB
==> Running `brew cleanup nmap`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
➜ /usr/local/Cellar >
➜ /usr/local/Cellar >nmap --version
Nmap version 7.92 ( https://nmap.org )
Platform: x86_64-apple-darwin21.1.0
Compiled with: nmap-liblua-5.3.5 openssl-1.1.1l nmap-libssh2-1.9.0 libz-1.2.11 nmap-libpcre-7.6 libpcap-1.9.1 nmap-libdnet-1.12 ipv6
Compiled without:
Available nsock engines: kqueue poll select
➜ /usr/local/Cellar >
posted @ 2021-12-18 13:57  That's_it  阅读(6047)  评论(0编辑  收藏  举报