Help us understand the problem. What is going on with this article?

Macでawkを実行するとエラー: "dyld: Library not loaded: /usr/local/opt/readline/lib/libreadline.7.dylib" となる問題の解決法

More than 1 year has passed since last update.

解決したいこと

awkを実行すると以下のエラーが発生しました。
(エラーが発生するようになった原因は不明で、調査中です)

$ awk
dyld: Library not loaded: /usr/local/opt/readline/lib/libreadline.7.dylib
  Referenced from: /usr/local/bin/awk
  Reason: image not found
Abort trap: 6

解決法

解決法はreadlineをインストールし直すです。

/usr/local/opt/readline/lib/libreadline.7.dylibがnot foundといっていて、実際に存在を確認してもなかったので、入れ直せばいいと思い入れ直したら、うまくいきました。以下は解決の手順です。

以下のようにbrew info readlineで利用可能なバージョンを調べます。libreadline.7.dylib7が含まれていたので、バージョンは7系が良さそうかなと思い、7系の最新の7.0.5が良さそうです。

$brew info readline
https://tiswww.case.edu/php/chet/readline/rltop.html
/usr/local/Cellar/readline/6.3.8 (46 files, 2.0MB)
  Poured from bottle on 2015-09-11 at 23:22:41
/usr/local/Cellar/readline/7.0 (45 files, 2MB)
  Poured from bottle on 2016-10-01 at 06:49:56
/usr/local/Cellar/readline/7.0.1 (46 files, 2MB)
  Poured from bottle on 2017-01-24 at 13:25:38
/usr/local/Cellar/readline/7.0.3_1 (46 files, 1.5MB)
  Poured from bottle on 2017-03-23 at 13:40:32
/usr/local/Cellar/readline/7.0.5 (46 files, 1.5MB)
  Poured from bottle on 2018-10-02 at 11:09:53
/usr/local/Cellar/readline/8.0.0 (48 files, 1.5MB)
  Poured from bottle on 2019-01-23 at 17:00:02

あとは、以下のコマンドを打って、無事に解決しました。

$ brew switch readline 7.0.5

以下のように無事にヘルプが出るようになりました。

 awk
Usage: awk [POSIX or GNU style options] -f progfile [--] file ...
Usage: awk [POSIX or GNU style options] [--] 'program' file ...
POSIX options:      GNU long options: (standard)
    -f progfile     --file=progfile
    -F fs           --field-separator=fs
    -v var=val      --assign=var=val
Short options:      GNU long options: (extensions)
    -b          --characters-as-bytes
    -c          --traditional
    -C          --copyright
    -d[file]        --dump-variables[=file]
    -D[file]        --debug[=file]
    -e 'program-text'   --source='program-text'
    -E file         --exec=file
...

参考

nwtgck
最近はScrapbox → https://scrapbox.io/nwtgck
https://scrapbox.io/nwtgck
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした