0
0

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 3 years have passed since last update.

VSCodeのRemoteSSH先にてcodeコマンドが使えない場合の一対処

Last updated at Posted at 2022-02-14

概要

VSCodeにてGCP上のインスタンスにて開発環境を構築しているので、VSCodeのRemoteSSHを用いてGCP上のインスタンスに接続して、開発作業を行なっている者だ。今回、codeコマンドがある日突然RemoteSSH先のVSCodeにて使用できなくなったので、その対処法を下記に示す。ざっと調べた限りでは、クリティカルな解決方法はなかったので備忘録的に記載する。尚、筆者はzshを用いてる。

事象

RemoteSSH先のVSCodeのTerminalにて下記の事象が発生した。

$ code
zsh: command not found: code

原因

/home/{USER_NAME}/.vscode-server/bin/{COMMIT}/bin にPATHが通っているのが通常の状態なのだが、その配下にcodeが存在しないため、not foundになる。では、どこにcode が存在しているかというと、/home/{USER_NAME}/.vscode-server/bin/{COMMIT}/bin /remote-cli/である。どうやら配置が変わったのかわからないが、PATHが通ってないだけなら話が早い

$ echo $PATH | grep vscode
PATH={OTHER_PATHs}:/home/{USER_NAME}/.vscode-server/bin/{COMMIT}/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/usr/local/go/bin

$ pwd
/home/{USER_NAME}/.vscode-server/bin/{COMMIT}/bin

$ tree
.
├── code-server
├── helpers
│   └── browser.sh
└── remote-cli
    └── code

解決

下記を.zshrcに追加する(bashなら.bash_profileやら.bashrcやらに)ことで、PATHをremote-cliまで通してあげれば良い

# vscode
if [[ ! -z VSCODE_IPC_HOOK_CLI ]]; then
	for i in $(ls ~/.vscode-server/bin); do
		export PATH=$HOME/.vscode-server/bin/$i/bin/remote-cli:$PATH
	done
fi
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?