n now works on windows 10 (using windows subsystem for linux)

Created on 11 Jun 2018  ยท  10Comments  ยท  Source: tj/n

n now works on Windows 10 (Windows Subsystem For Linux):

If enough people find that this works for them, the docs / README.md could be changed to reflect this.

Windows version

_Windows 10 Home, Version 10.0.17134 Build 17134_

Version of N

_n --version output: 2.1.11_

How I installed N

Start up windows subsystem for linux bash prompt by typing Win key followed by wsl
Then, install using the following sequence:

sudo apt-get install nodejs-legacy
sudo apt-get install npm
sudo npm install -g n
sudo n lts
sudo npm install npm@lts -g
sudo chown -R $USER:$(id -gn $USER) /home/aal/.config

IMPORTANT NOTE:

  • change the name in the path when using the chown command above to reflect your home directory in WSL.
  • Then, exit the shell and start it up again.

After restarting the WSL bash window:

$ node --version
  v8.11.2
$ npm --version
  5.6.0

Tried installing other node versions, using

sudo n install latest

And got:

$ node --version
v10.4.0
$ npm --version
6.1.0
docs

Most helpful comment

Anyone coming here who installed n like this:

curl -L https://git.io/n-install | bash

On the off chance that you have the same problems that I did where the node version installed by n was not the one being referenced, I have a little tidbit for you. When I would n 9.6.1 it would fetch and install 9.6.1, but would then say that 8.11.x was installed. I think this has something to do with how node is linked or referenced or something.

If which -a node returns multiple directories, rm all of them except the one with n in the path. This worked for me, whether it's intended or not.

Now, when I which -a node I only see the path to node as installed by n.

Hope this helps more than it confuses! ๐Ÿคทโ€โ™‚๏ธ

All 10 comments

Worked for me, I used n-install at first, but that wouldn't work being directly called through bash.exe. However, the method you've suggested works just fine.

Tried installing other node versions, using

sudo n install latest

Should be sudo n latest.

I can confirm that this is working on the latest version of Windows 10 Pro! ๐ŸŽ‰

_Windows 10 Pro version 1803 build 17134.165_

Anyone coming here who installed n like this:

curl -L https://git.io/n-install | bash

On the off chance that you have the same problems that I did where the node version installed by n was not the one being referenced, I have a little tidbit for you. When I would n 9.6.1 it would fetch and install 9.6.1, but would then say that 8.11.x was installed. I think this has something to do with how node is linked or referenced or something.

If which -a node returns multiple directories, rm all of them except the one with n in the path. This worked for me, whether it's intended or not.

Now, when I which -a node I only see the path to node as installed by n.

Hope this helps more than it confuses! ๐Ÿคทโ€โ™‚๏ธ

๐Ÿ’ป Windows version

Microsoft Windows [Version 10.0.18362.175]
(c) 2019 Microsoft Corporation. All rights reserved.

C:\Users\Virgil>

โญ•๏ธ WSL Distro

$ lsb_release -ds
Ubuntu 18.04.2 LTS
$ uname -rom
4.4.0-18362-Microsoft x86_64 GNU/Linux

โš™๏ธ Version of n

$ n --version
4.1.0

Or the more extended versions:

$ has n node npm nvm npx yarn
โœ“ n 4.1.0
โœ“ node 10.16.0
โœ“ npm 6.9.0
โœ— nvm
โœ“ npx 6.9.0
โœ“ yarn 1.16.0
โœ“ git 2.21.0
$ n latest
$ has n node npm nvm npx yarn
โœ“ n 4.1.0
โœ“ node 12.4.0
โœ“ npm 6.9.0
โœ— nvm
โœ“ npx 6.9.0
โœ“ yarn 1.16.0
โœ“ git 2.21.0

binary locations

$ type -p n node npm npx yarn
/home/virgil/.local/n/bin/n
/home/virgil/.local/n/bin/node
/home/virgil/.local/n/bin/npm
/home/virgil/.local/n/bin/npx
/usr/bin/yarn

๐Ÿฅ‡ [has] is from here

๐Ÿ“‹ How I installed N

via n-install

$ nvm unload
$ curl -#L https://git.io/n-install | N_PREFIX=$HOME/.local/n bash -s -- -y lts 0.11


n-install output

######################################################################## 100.0%
-- Cloning https://github.com/tj/n to '/home/virgil/.local/n/n/.repo'...
-- Running local n installation to '/home/virgil/.local/n/bin'...
-- Shell initialization file '/home/virgil/.bashrc' updated.
-- Installing helper scripts in '/home/virgil/.local/n/bin'...
-- Installing the requested Node.js version(s)...
   1 of 2: lts...

     install : node-v10.16.0
       mkdir : /home/virgil/.local/n/n/versions/node/10.16.0
       fetch : https://nodejs.org/dist/v10.16.0/node-v10.16.0-linux-x64.tar.gz
######################################################################## 100.0%
   installed : v10.16.0

   2 of 2: 0.11...

     install : node-v0.11.16
       mkdir : /home/virgil/.local/n/n/versions/node/0.11.16
       fetch : https://nodejs.org/dist/v0.11.16/node-v0.11.16-linux-x64.tar.gz
######################################################################## 100.0%
   installed : v0.11.16

=== n successfully installed.
  The active Node.js version is: v10.16.0

  Run `n -h` for help.
  To update n later, run `n-update`.
  To uninstall, run `n-uninstall`.

  IMPORTANT: OPEN A NEW TERMINAL TAB/WINDOW or run `. /home/virgil/.bashrc`
             before using n and Node.js.
===

And the whole reason I replied to this issue:

sudo chown -R $USER:$(id -gn $USER) /home/aal/.config

sudo chown -R $USER:$(id -gn $USER) ${XDG_CONFIG_HOME:-"$HOME/.config"}

๐Ÿค“ If you are going to bother with id -gn instead of $USER:, use the correct environment variables.

Virgil

n now works on Windows 10 (Windows Subsystem For Linux):

If enough people find that this works for them, the docs / README.md could be changed to reflect this.

Windows version

_Windows 10 Home, Version 10.0.17134 Build 17134_

Version of N

_n --version output: 2.1.11_

How I installed N

Start up windows subsystem for linux bash prompt by typing Win key followed by wsl
Then, install using the following sequence:

sudo apt-get install nodejs-legacy
sudo apt-get install npm
sudo npm install -g n
sudo n lts
sudo npm install npm@lts -g
sudo chown -R $USER:$(id -gn $USER) /home/aal/.config

IMPORTANT NOTE:

  • change the name in the path when using the chown command above to reflect your home directory in WSL.
  • Then, exit the shell and start it up again.

After restarting the WSL bash window:

$ node --version
  v8.11.2
$ npm --version
  5.6.0

Tried installing other node versions, using

sudo n install latest

And got:

$ node --version
v10.4.0
$ npm --version
6.1.0

Dude, you are awesome!
This topic should be pinned in the readme of the project!
"Petition" to do that :D

image

Mirror looks like not working through.

@gengjiawen
Check the documentation for sudo. Typically environment variables are not preserved for the sudo context unless you specify an option.

e.g.

The -E (preserve environment) option indicates to the security policy that the user wishes to preserve their existing environment variables.

So you would run:

sudo -E n latest

Here's how i did it, to avoid having to use sudo for either npm or n:

sudo apt-get install npm
sudo mkdir -p /usr/local/n
sudo chown -R $(whoami) /usr/local/n
sudo chown -R $(whoami) /usr/local/bin /usr/local/lib /usr/local/include /usr/local/share
npm install -g n
n lts

That looks like "normal" @jonathan-annett , exciting!

For interest in changes which might be required to support more than WSL, PR for nvm to "Make it work on Windows with WSL, MSYS, Cygwin": https://github.com/nvm-sh/nvm/pull/2391

Was this page helpful?
0 / 5 - 0 ratings