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

Visual Studio Code codeコマンドが存在しないと言われる (パス通し)

Posted at

目的

  • codeコマンドが存在しないと言われ他の方の解決策では解決しなかったので独自?の方法をまとめる

実施環境

  • ハードウェア環境
項目 情報
OS macOS Catalina(10.15.5)
ハードウェア MacBook Pro (13-inch, 2020, Four Thunderbolt 3 ports)
プロセッサ 2 GHz クアッドコアIntel Core i5
メモリ 32 GB 3733 MHz LPDDR4
グラフィックス Intel Iris Plus Graphics 1536 MB
  • ソフトウェア環境
項目 情報 備考
Visual Studio Codeバージョン 1.47.3 こちらの方法で導入→Mac Visual Studio Code 導入方法 VSCode ダウンロードから日本語化対応まで~画像付き導入解説~

前提情報

問題までの経緯

  1. Visual Studio Codeで開きたいファイルをVisual Studio Codeのターミナルから下記コマンドで開こうとした。

    $ code ファイル名
    

問題

  1. 下記のエラーが発生し$ codeコマンドでファイルを開くことができない。

    bash: code: command not found
    

問題解決までの経緯

  1. 下記の方法を用いて$ codeコマンドを使用できる様にしたが相変わらず「bash: code: command not found」のエラーが出る。

  2. 何度実施しても前述の方法では解決しない。ssh接続先の再起動、ssh接続元の再起動なども実施した。

  3. コマンドパスを.bash_profileに記載することにした。

  4. codeコマンドが格納されている場所を探す。ssh接続先にそれらしいパスを発見した。コマンドまでのフルパスを下記に記載する。

    /home/ec2-user/.vscode-server/bin/91899dcef7b8110878ea59626991a18c8a6a1b3e/bin/code
    
  5. 下記コマンドを実行してファイルが開くことができるか確認し、目測通りtest.txtをVisual Studio Codeのウインドウで開くことができた。

    $ /home/ec2-user/.vscode-server/bin/91899dcef7b8110878ea59626991a18c8a6a1b3e/bin/code ~/test.txt
    
  6. コマンドが格納されているフルパスがわかったので.bash_profileに情報を記載しパスを通す。

  7. 下記コマンドを実行して.bash_profileのバックアップを用意する。

    $ cp ~/.bash_profile ~/.bash_profile_org
    
  8. 下記コマンドを実行して.bash_profileを開く。

    $ vi ~/.bash_profile
    
  9. 下記の内容を追記する。

    .bash_profile
    export PATH=$PATH:/home/ec2-user/.vscode-server/bin/91899dcef7b8110878ea59626991a18c8a6a1b3e/bin
    
  10. 下記コマンドを実行して.bash_profileを読み込む。

    $ source ~/.bash_profile
    
  11. 下記コマンドを実行して$ codeコマンドが使える様になったのか確認する。

    $ code 開きたいファイル名
    

補足情報

  • 本方法はプラグインを用いたssh接続先で$ codeコマンドが使用できない問題に関しての記事である。
  • MacなどでもVisual Studio Codeのシステムファイル内のbinディレクトリ直下のcodeコマンドまでのパスを.bash_profileに記載してあげることで$ codeコマンドまでパスを通すことは可能である。
  • Visual Studio Codeのウインドウ上からの$ codeコマンドのアクティベートに失敗する場合は一度試してみるといいのかもしれない。
0
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
0
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?