1
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.

WSL2のUbuntu20.04 でroot以外のユーザーでnpmコマンドが使えない

Posted at

#環境

  • Windows 10 Pro
  • WSL2
  • Ubuntu20.04

#状況
アプリケーション一覧からUbuntu20.04を起動し

sudo apt install npm

でnpmをインストールした後,

npm --version

実行すると,

-bash: /mnt/c/Program Files/nodejs/npm: /bin/sh^M: bad interpreter: No such file or directory
sudo su

してからrootユーザーで実行すると普通にバージョン情報が出力される.
あと, PowerShell経由でwslコマンドで実行すると発生しない.

#改行コードをCRLFからLFへ変更

色々調べてると改行コードが悪さしてそうだったので,
CRLFからLFに変える

無精してVSCodeで変更
screen_npm_CRLF_to_LF.JPG
CRLFを選択して,
screen_npm_CRLF_to_LF.png
LFを選択.

一旦, exitして再起動.

$ npm -v
6.14.4

#参考

1
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
1
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?