What is the recommended way of installing for Windows Subsystem for Linux (WSL)?

I was originally working with npm via its Windows installer, and running it in PowerShell. But using that to install https://github.com/aws-amplify/amplify-cli didn’t work well, so I setup Bash/Ubuntu/WindowsSubsystemForLinux, uninstalled npm for Windows, and tried sudo apt-get install node and the same for npm. After that, npm install in my project folders usually breaks due to ENOENT or an untar failure.

I googled for the recommended way of installing npm for WSL and found suggestions like https://www.youtube.com/watch?v=hiWWXCZbY6A It involves replacing the npm installed via sudo apt-get with one via β€˜n’.

Would you provide a guide about the recommended way of installing for WSL.

This trace shows that I’ve tried to install npm (on WSL) in the recommended ways. But I still get the following whenever I try β€œnpm install”:

npm ERR! tar.unpack untar error /home/vada/.npm/rxjs/6.5.2/package.tgz
npm ERR! tar.unpack untar error /home/vada/.npm/moment/2.24.0/package.tgz
npm ERR! tar.unpack untar error /home/vada/.npm/core-js/1.2.7/package.tgz
npm ERR! tar.unpack untar error /home/vada/.npm/caniuse-lite/1.0.30000974/package.tgz
npm ERR! tar.unpack untar error /home/vada/.npm/core-js/3.0.1/package.tgz

If some entries in my package.json below are obsolete, how do I auto-update them?

{
  "name": "modality-web-view",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "aws-amplify": "^1.1.28",
    "glamor": "^2.20.40",
    "moment": "^2.24.0",
    "query-string": "^6.5.0",
    "react": "^16.8.6",
    "react-bootstrap": "^1.0.0-beta.8",
    "react-datepicker": "^2.5.0",
    "react-dom": "^16.8.6",
    "react-files": "^2.4.8",
    "react-loading-overlay": "^1.0.1",
    "react-router-dom": "^4.3.1",
    "react-scripts": "^3.0.1",
    "ts-react-json-table": "^0.1.1",
    "typescript": "^3.4.5"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ]
}

Following Installing/upgrading npm I tried:

$ sudo npm i -g npm@latest
[sudo] password for vada:
/usr/local/lib
└── (empty)

npm ERR! Linux 4.4.0-17134-Microsoft
npm ERR! argv "/usr/local/bin/node" "/usr/bin/npm" "i" "-g" "npm@latest"
npm ERR! node v10.16.0
npm ERR! npm  v3.10.10
npm ERR! path /usr/local/lib/node_modules/.staging/p-locate-f1fa4a30
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall rename

npm ERR! enoent ENOENT: no such file or directory, rename '/usr/local/lib/node_modules/.staging/p-locate-f1fa4a30' -> '/usr/local/lib/node_modules/npm/node_modules/p-locate'
npm ERR! enoent ENOENT: no such file or directory, rename '/usr/local/lib/node_modules/.staging/p-locate-f1fa4a30' -> '/usr/local/lib/node_modules/npm/node_modules/p-locate'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! Please include the following file with any support request:
npm ERR!     /mnt/e/[deleted]/webview/npm-debug.log
npm ERR! code 1


$ curl http://npmjs.org/install.sh | sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0

$ npm --version
3.10.10

$ node --version
v10.16.0

Removed node_modules/ in my project folder

webview$ npm install
npm WARN deprecated core-js@1.2.7: core-js@<2.6.8 is no longer maintained. Please, upgrade to core-js@3 or at least to actual version of core-js@2.
npm WARN deprecated left-pad@1.3.0: use String.prototype.padStart()
npm WARN deprecated flatten@1.0.2: I wrote this module a very long time ago; you should use something else.
npm ERR! tar.unpack untar error /home/vada/.npm/rxjs/6.5.2/package.tgz
npm ERR! tar.unpack untar error /home/vada/.npm/moment/2.24.0/package.tgz
npm ERR! tar.unpack untar error /home/vada/.npm/core-js/1.2.7/package.tgz
npm ERR! tar.unpack untar error /home/vada/.npm/caniuse-lite/1.0.30000974/package.tgz
npm ERR! tar.unpack untar error /home/vada/.npm/core-js/3.0.1/package.tgz
modality-web-view@0.1.0 /mnt/e/[deleted]/webview
β”œβ”€β”€ @babel/code-frame@7.0.0  extraneous
β”œβ”€β”€ @babel/core@7.4.3  extraneous
β”œβ”€β”€ @babel/helper-plugin-utils@7.0.0  extraneous
β”œβ”€β”€ @babel/plugin-syntax-object-rest-spread@7.2.0  extraneous
β”œβ”€β”€ @cnakazawa/watch@1.0.3  extraneous
β”œβ”€β”€ @jest/console@24.7.1  extraneous
β”œβ”€β”€ @jest/environment@24.8.0  extraneous
β”œβ”€β”€ @jest/test-sequencer@24.8.0  extraneous
β”œβ”€β”€ @webassemblyjs/ast@1.8.5  extraneous
β”œβ”€β”¬ aws-amplify@1.1.28
β”‚ β”œβ”€β”¬ @aws-amplify/analytics@1.2.16
β”‚ β”‚ └── uuid@3.3.2
β”‚ β”œβ”€β”¬ @aws-amplify/api@1.0.35
β”‚ β”‚ β”œβ”€β”€ @types/zen-observable@0.5.4
β”‚ β”‚ β”œβ”€β”¬ axios@0.17.1
β”‚ β”‚ β”‚ β”œβ”€β”¬ follow-redirects@1.7.0
β”‚ β”‚ β”‚ β”‚ └─┬ debug@3.2.6
β”‚ β”‚ β”‚ β”‚   └── ms@2.1.2
β”‚ β”‚ β”‚ └── is-buffer@1.1.6
β”‚ β”‚ β”œβ”€β”¬ graphql@0.13.0
β”‚ β”‚ β”‚ └── iterall@1.1.4
β”‚ β”‚ └── zen-observable@0.8.14
β”‚ β”œβ”€β”¬ @aws-amplify/auth@1.2.24
β”‚ β”‚ β”œβ”€β”¬ amazon-cognito-identity-js@3.0.12
β”‚ β”‚ β”‚ β”œβ”€β”¬ buffer@4.9.1
β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ base64-js@1.3.0
β”‚ β”‚ β”‚ β”‚ └── isarray@1.0.0
β”‚ β”‚ β”‚ └── js-cookie@2.2.0
β”‚ β”‚ └── crypto-js@3.1.9-1
β”‚ β”œβ”€β”€ @aws-amplify/cache@1.0.27
β”‚ β”œβ”€β”¬ @aws-amplify/core@1.0.27
β”‚ β”‚ β”œβ”€β”¬ aws-sdk@2.329.0
β”‚ β”‚ β”‚ β”œβ”€β”€ events@1.1.1
β”‚ β”‚ β”‚ β”œβ”€β”€ ieee754@1.1.8
β”‚ β”‚ β”‚ β”œβ”€β”€ jmespath@0.15.0
β”‚ β”‚ β”‚ β”œβ”€β”€ querystring@0.2.0
β”‚ β”‚ β”‚ β”œβ”€β”€ sax@1.2.1
β”‚ β”‚ β”‚ β”œβ”€β”€ url@0.10.3
β”‚ β”‚ β”‚ β”œβ”€β”€ uuid@3.1.0
β”‚ β”‚ β”‚ └─┬ xml2js@0.4.19
β”‚ β”‚ β”‚   └── xmlbuilder@9.0.7
β”‚ β”‚ └─┬ url@0.11.0
β”‚ β”‚   └── punycode@1.3.2
β”‚ β”œβ”€β”€ @aws-amplify/interactions@1.0.30
β”‚ β”œβ”€β”€ @aws-amplify/pubsub@1.0.28
β”‚ β”œβ”€β”€ @aws-amplify/storage@1.0.30
β”‚ β”œβ”€β”€ @aws-amplify/ui@1.0.19
β”‚ └── @aws-amplify/xr@0.1.17
β”œβ”€β”¬ glamor@2.20.40
β”‚ β”œβ”€β”¬ inline-style-prefixer@3.0.8
β”‚ β”‚ β”œβ”€β”€ bowser@1.9.4
β”‚ β”‚ └─┬ css-in-js-utils@2.0.1
β”‚ β”‚   β”œβ”€β”€ hyphenate-style-name@1.0.3
β”‚ β”‚   └── isobject@3.0.1
β”‚ β”œβ”€β”€ object-assign@4.1.1
β”‚ β”œβ”€β”¬ prop-types@15.7.2
β”‚ β”‚ └── react-is@16.8.6
β”‚ └── through@2.3.8
β”œβ”€β”¬ query-string@6.7.0
β”‚ β”œβ”€β”€ decode-uri-component@0.2.0
β”‚ β”œβ”€β”€ split-on-first@1.1.0
β”‚ └── strict-uri-encode@2.0.0
β”œβ”€β”¬ react@16.8.6
β”‚ β”œβ”€β”¬ loose-envify@1.4.0
β”‚ β”‚ └── js-tokens@4.0.0
β”‚ └── scheduler@0.13.6
β”œβ”€β”¬ react-datepicker@2.7.0
β”‚ β”œβ”€β”€ classnames@2.2.6
β”‚ β”œβ”€β”€ date-fns@2.0.0-alpha.34
β”‚ └── react-onclickoutside@6.8.0
β”œβ”€β”€ react-dom@16.8.6
β”œβ”€β”€ react-files@2.4.8
β”œβ”€β”¬ react-loading-overlay@1.0.1
β”‚ β”œβ”€β”¬ emotion@10.0.9
β”‚ β”‚ β”œβ”€β”¬ babel-plugin-emotion@10.0.13
β”‚ β”‚ β”‚ β”œβ”€β”¬ @babel/helper-module-imports@7.0.0
β”‚ β”‚ β”‚ β”‚ └─┬ @babel/types@7.4.4
β”‚ β”‚ β”‚ β”‚   β”œβ”€β”€ esutils@2.0.2
β”‚ β”‚ β”‚ β”‚   β”œβ”€β”€ lodash@4.17.11
β”‚ β”‚ β”‚ β”‚   └── to-fast-properties@2.0.0
β”‚ β”‚ β”‚ β”œβ”€β”€ @emotion/hash@0.7.1
β”‚ β”‚ β”‚ β”œβ”€β”€ @emotion/memoize@0.7.1
β”‚ β”‚ β”‚ β”œβ”€β”¬ @emotion/serialize@0.11.7
β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ @emotion/unitless@0.7.3
β”‚ β”‚ β”‚ β”‚ └── csstype@2.6.5
β”‚ β”‚ β”‚ β”œβ”€β”¬ babel-plugin-macros@2.6.1
β”‚ β”‚ β”‚ β”‚ β”œβ”€β”¬ cosmiconfig@5.2.1
β”‚ β”‚ β”‚ β”‚ β”‚ β”œβ”€β”¬ import-fresh@2.0.0
β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”œβ”€β”¬ caller-path@2.0.0
β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ └─┬ caller-callsite@2.0.0
β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚   └── callsites@2.0.0
β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ └── resolve-from@3.0.0
β”‚ β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ is-directory@0.3.1
β”‚ β”‚ β”‚ β”‚ β”‚ β”œβ”€β”¬ js-yaml@3.13.1
β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”œβ”€β”¬ argparse@1.0.10
β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ └── sprintf-js@1.0.3
β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ └── esprima@4.0.1
β”‚ β”‚ β”‚ β”‚ β”‚ └─┬ parse-json@4.0.0
β”‚ β”‚ β”‚ β”‚ β”‚   β”œβ”€β”¬ error-ex@1.3.2
β”‚ β”‚ β”‚ β”‚ β”‚   β”‚ └── is-arrayish@0.2.1
β”‚ β”‚ β”‚ β”‚ β”‚   └── json-parse-better-errors@1.0.2
β”‚ β”‚ β”‚ β”‚ └─┬ resolve@1.11.0
β”‚ β”‚ β”‚ β”‚   └── path-parse@1.0.6
β”‚ β”‚ β”‚ β”œβ”€β”€ babel-plugin-syntax-jsx@6.18.0
β”‚ β”‚ β”‚ β”œβ”€β”¬ convert-source-map@1.6.0
β”‚ β”‚ β”‚ β”‚ └── safe-buffer@5.1.2
β”‚ β”‚ β”‚ β”œβ”€β”€ escape-string-regexp@1.0.5
β”‚ β”‚ β”‚ β”œβ”€β”€ find-root@1.1.0
β”‚ β”‚ β”‚ └── source-map@0.5.7
β”‚ β”‚ └─┬ create-emotion@10.0.9
β”‚ β”‚   β”œβ”€β”¬ @emotion/cache@10.0.9
β”‚ β”‚   β”‚ β”œβ”€β”€ @emotion/stylis@0.8.3
β”‚ β”‚   β”‚ └── @emotion/weak-memoize@0.2.2
β”‚ β”‚   β”œβ”€β”€ @emotion/sheet@0.9.2
β”‚ β”‚   └── @emotion/utils@0.11.1
β”‚ └─┬ react-transition-group@2.9.0
β”‚   β”œβ”€β”€ dom-helpers@3.4.0
β”‚   └── react-lifecycles-compat@3.0.4
β”œβ”€β”¬ react-router-dom@4.3.1
β”‚ β”œβ”€β”¬ history@4.9.0
β”‚ β”‚ β”œβ”€β”¬ @babel/runtime@7.4.5
β”‚ β”‚ β”‚ └── regenerator-runtime@0.13.2
β”‚ β”‚ β”œβ”€β”€ resolve-pathname@2.2.0
β”‚ β”‚ β”œβ”€β”€ tiny-invariant@1.0.4
β”‚ β”‚ β”œβ”€β”€ tiny-warning@1.0.2
β”‚ β”‚ └── value-equal@0.4.0
β”‚ β”œβ”€β”€ invariant@2.2.4
β”‚ β”œβ”€β”¬ react-router@4.3.1
β”‚ β”‚ β”œβ”€β”€ hoist-non-react-statics@2.5.5
β”‚ β”‚ └─┬ path-to-regexp@1.7.0
β”‚ β”‚   └── isarray@0.0.1
β”‚ └── warning@4.0.3
β”œβ”€β”€ ts-react-json-table@0.1.2
└── typescript@3.5.2

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.0.6 (node_modules/react-scripts/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.0.6: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules/jest-haste-map/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: caniuse-lite@1.0.30000974 (node_modules/caniuse-lite):
npm WARN enoent SKIPPING OPTIONAL DEPENDENCY: ENOENT: no such file or directory, utime '/mnt/e/[deleted]/webview/node_modules/.staging/caniuse-lite-81405ece/data/features/stream.js'
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: core-js@3.0.1 (node_modules/react-app-polyfill/node_modules/core-js):
npm WARN enoent SKIPPING OPTIONAL DEPENDENCY: ENOENT: no such file or directory, utime '/mnt/e/[deleted]/webview/node_modules/.staging/core-js-8338bf89/modules/esnext.array.last-index.js'
npm ERR! Linux 4.4.0-17134-Microsoft
npm ERR! argv "/usr/local/bin/node" "/usr/bin/npm" "install"
npm ERR! node v10.16.0
npm ERR! npm  v3.10.10
npm ERR! path /mnt/e/[deleted]/webview/node_modules/.staging/rxjs-6b1c55b8/_esm2015/internal/observable/from.js
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall utime

npm ERR! enoent ENOENT: no such file or directory, utime '/mnt/e/[deleted]/webview/node_modules/.staging/rxjs-6b1c55b8/_esm2015/internal/observable/from.js'
npm ERR! enoent ENOENT: no such file or directory, utime '/mnt/e/[deleted]/webview/node_modules/.staging/rxjs-6b1c55b8/_esm2015/internal/observable/from.js'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! Please include the following file with any support request:
npm ERR!     /mnt/e/[deleted]/webview/npm-debug.log

I have made some progress. First, I tried everything suggested in https://github.com/npm/npm/issues/5133 but none of these fixed the problem: Running WSL as Admin, using sudo, npm cache clean. However, after all that, when I manually installed each module version that failed untar, it succeeded…with one exception. For the last module, I changed focus to another app for awhile, and when I returned I saw an untar error again. But retrying it while not changing focus allowed it to succeed.

So, I think there could be multiple causes of failure:

  • npm is not handling network or filesystem errors well, perhaps due to doing them asynchronously
  • Running npm under sudo might take so long that the permissions granted by sudo expire midway. For example, I’ve had to re-enter my sudo password a few times today in the same WSL window.
  • Some filepaths during installs are too long for Windows

The sudo expiration can be extended: https://unix.stackexchange.com/questions/77356/how-long-is-the-password-for-executing-a-command-with-sudo-cached

This is recently enough that I thought to ask if these are problems using WSL or WSL2?

This is recently enough that I thought to ask if these are problems using WSL or WSL2?

I wasn’t sure what you meant about β€œWSL2”, and google led me to https://github.com/Microsoft/WSL/issues/1728#issuecomment-452751912 which advises:

$ cmd.exe /c β€œsysteminfo” | grep β€œ^OS Version”
OS Version: 10.0.17134 N/A Build 17134

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.6 LTS
Release: 14.04
Codename: trusty

It’s still the case that whenever I try β€œnpm install” (in my @aws-amplify/cli project) there’s an ENOENT error ever time, and it’s usually about a different file than previous times.

Here’s some other version info:
$ node --version
v10.16.0

$ npm --version
3.10.10

I’m using only executables installed via β€˜sudo apt-get’, not Windows executables.

The WSL I was using runs from C:\Windows\System32\bash.exe This seems to be an outdated WSL. I later installed Ubuntu 18.04 LTS from the Microsoft Store app – the new WSL – and I had no ENOENT errors while installing npm or any modules.