3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[macOS] VSCode がターミナルから起動しない

Last updated at Posted at 2023-06-22

起動しなくなった

https://www.chickensblog.com/vscode-terminal/
こちらのサイトを参考にして macOS のターミナルから code コマンドで VSCode を起動できるにようにしていたのですが、ある日気づいたら起動できなくなっていました。

% code
zsh: command not found: code

原因はリンク切れ

/usr/local/bin にある code コマンドへのシンボリックリンクがリンク切れになっていました。

シンボリックリンクファイルは存在しているものの
% ls -l /usr/local/bin
total 0
lrwxr-xr-x  1 root  wheel  167  5 26 17:54 code -> /private/var/folders/...途中省略.../Visual Studio Code.app/Contents/Resources/app/bin/code

リンク先のパスを直接 ls コマンドで確認するとエラーとなる
% ls "/private/var/folders/...途中省略.../Visual Studio Code.app/Contents/Resources/app/bin/code"
ls: /private/var/folders/...途中省略.../Visual Studio Code.app/Contents/Resources/app/bin/code: No such file or directory

対策1(非推奨)

shift + command + P から shell と入力し、code コマンドをアンインストールしたのちに再度インストールします。
これでリンクが再生成され code コマンドで VSCode が起動するようになりました。

image.png

対策2(推奨)

実は対策1では不十分でした。
一時的には起動できるようになるものの何らかのタイミング(おそらくアップデート)でまたリンク切れが発生し起動できなくなります。
対策1を行った場合は、対策1の code コマンドを PATH からアンインストールしたのち下記設定を実施してください。

.zshrc
export PATH="/Applications/Visual Studio Code.app/Contents/Resources/app/bin":$PATH

source ~/.zshrc

シンボリックリンクではなく Applications から直接 PATH 設定することでリンク切れの影響を受けることなく起動できるようになります。

3
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
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?