LoginSignup
2
2

More than 1 year has passed since last update.

kubectlをMacにcurl経由でinstallした時にcomplete:13: command not found: compdefのエラーが出たときの解消方法

Last updated at Posted at 2022-07-05

KubectlをMacにinstallした時にエラーが出他のでその時の解消方法のメモ

現象

以下の手順でインストールを試みたところ、sourceコマンド実行時にエラーが出た。

.terminal
$ curl -O "https://storage.googleapis.com/kubernetes-release/release/v1.18.2/bin/darwin/amd64/kubectl"
$ chmod -x kubectl
$ sudo -x kubectl /usr/local/bin/kubectl

# for zsh user
$ source <(kubectl completion zsh) # -> これを実行した時にerror complete:13: command not found: compdef

解決策

調べてみたところ、他のCLIのインストールでも同様のケースがあり、同じ方法で解決することができた。以下の二つのコマンドを実行した後に、再度 source <(kubectl completion zsh)を実行すると動作するとエラーが出なくなる。

.terminal
$ autoload -Uz compinit
$ compinit

compinitコマンドで毎回メッセージが出る場合

二つ目の compinitコマンド実行時に毎回

.zsh
$ compinit
# Ignore insecure directories and continue [y] or abort compinit [n]?

とメッセージが表示されていて、そのたびにyを押すのが面倒だったので、以下のコマンドを実行したところ解消した。

.zsh
$ compaudit | xargs chmod g-w

余談

毎回シェル起動時に上の手順を手動で実行するのは面倒なので、 .zshrcに追記した

.zshrc
$ autoload -Uz compinit && compinit
$ source <(kubectl completion zsh)

参考文献

compinitのエラーが出た時の解消方法
https://github.com/zsh-users/zsh-completions/issues/680

compinitコマンドで毎回メッセージが出るところを解消するのに必要なコマンド
https://qiita.com/kylasakerskog/items/736169f4477947cf7126

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2