Is there any way to install nodejs/npm in wsl ubuntu via bash script? - node.js

So i'm making a bash script to setup my Ubuntu distro in wsl2. I'm trying to install npm so i follow the Microsoft tutorial installing nvm -> then npm with nvm install --lts.
The thing is i can't find a way to install through nvm because nvm installs but then when i run nvm install --lts it doesn't work. Now microsoft says i have to reboot the terminal and it does work that way but i wonder if i can do it via the bash script, basically reloding the shell or opening a new one to install npm?
Thanks in advance

I would actually go ahead and look for an NPM that suites your needs with SSH. I then would automate the process with both an initial setup>wait with setTimeouts/intervals till server is back online and continue setup and when server is fully ready it will then begin to respond the way you need it to. No examples unfortunately but hope this helps. :)

Related

I have installed nodejs on windows how should i use it in WSL?

I am having problem using libraries installed on windows to WSL and vice versa. I don't want to install not just nodejs but other things twice just to use it in WSL and also in normal text editors like VS code, atom, etc.
The complete instruction can be found here set-up-on-wsl
If you are too busy to follow the link, follow these steps in the WSL:
Use curl to install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
For installing NodeJs (lts)
nvm install node --lts
You can also install specific node version. Check all commands uses by typing nvm in your terminal.
Done Node has been successfully installed in your WSL, nvm ls will list all the installations.
You can use the Node installed in your WSL for developing. Point to your working directory and use code . to open VSCode. Also, if you want to access your windows directories you can mount them by using /mnt/<dir>
If you face any issues during installation it is better to use the link I have provided above.
Also note that, the Node installed in the WSL can only be used, iff your working directory is in the WSL or is linked with your WSL(by using mnt).

Issues with installing nodeJS on a shared hosting plan

Here are the steps I am following:
First, I login to my account using SSH.
Then, I install nvm using
wget -qO- https://cdn.rawgit.com/creationix/nvm/master/install.sh | bash
Then, I restart the shell
Then, I install node using
nvm install stable
But, when I check for the version of the node using the following, it says 'command not found'
node --version
If it helps, here are other things I tried:
nvm list
Also, here are the contents of the .nvm folder (which is inside the root folder):
I suppose N/A indicates that node is not available.
To sum it up, is it possible at all to use node.js on a shared hosting plan? If, yes, what can I do to make it work?
PS: I have been getting suggestions to use other plans like Heroku etc. Although, I have already invested a lot in this shared hosting plan (on GoDaddy), so I would really like if I can host nodeJS applications here.
PPS: I am new to programming, so please bear with any ignorance.
Try installing node like this
nvm install node
Then, crucially
nvm alias default node
Now running
node -v
Should display correctly
First of all shared server wont allow you to install anything on their server.
If you can able to install node on your shared server then you are pretty lucky.
To run node --version command, the node command should be in your path. On shared server, it might not be allowed.
So I think you need to check with full path like `/usr/bin/node --version'
(check your installation path)

Node cli on Msysgit on WIndows 10

I recently decided to pick up Node on my personal laptop, which I upgraded to Windows 10, and the Node cli seems to hang when I try to run it.
Simply typing node on the console will not initiate the interface, and to do anything else I need to Ctrl+C out of it.
Additionally, running some npm commands take longer than they used to on my laptop. More noticeably, npm init seems to hang after confirming the information to be written to package.json.
Node version is 4.0.0
npm version is 2.14.2
Are there any known issues with Node and npm on Windows 10?
Edit:
After some troubleshooting, I've figured out the error only happens on Msysgit. Neither of the issues happen on the standard command prompt of Windows.
I had the same issue on Windows 7 with Node version 6.11.0 and Msysgit's MINGW64 terminal window.
The problem was caused by the an alias provided by Msysgit as demonstrated below:
$ alias node
alias node='winpty node.exe'
The solution is to run the command:
$ unalias node
Then node will run correctly.
You can add the unalias node command into your .bashrc file in your HOME directory to make this permanent.
Good luck!
Jeff

How can I get the slc command to work on Ubuntu?

I have installed Strongloop using npm install -g strongloop on my Ubuntu 14.04 server. The slc command does not work. It says
The program 'slc' is currently not installed. You can install it by typing:
sudo apt-get install heimdal-multidev
How can I get it to run the Strongloop CLI instead of looking for this package? I have added this to my PATH and it still doesn't work. Any ideas?
Other Strongloop commands, like sl-build work and strongloop is listed in npm list -g.
Ubuntu 14 with node.js 4.1.2
By default somehow slc is not created or not added to PATH.
I solved this problem by adding symlink:
sudo ln -s /usr/lib/node_modules/strongloop/bin/slc.js /usr/bin/slc
A soft link named slc should have been created at /usr/local/bin which will point to strongloop binary.
Please verify if the following exists.
/usr/local/lib/node_modules/strongloop/bin/slc
If no, then strongloop did not get installed successfully, otherwise verify the existence of the softlink slc at /usr/local/bin/.
/usr/local/bin/slc -> /usr/local/lib/node_modules/strongloop/bin/slc
If yes, then /usr/local/bin needs to be added to the $PATH, otherwise create the softlink and verify that /usr/local/binin $PATH.
Looks like the Node installation that optionally comes with a Digital Ocean Droplet installs to a different location that's not in $PATH. I'm pretty sure that was the issue. Anyways, I fixed it by spinning up a server without Node pre-installed and followed this guide. Just use npm install -g strongloop instead of strong-cli because the latter has been deprecated.
Ubuntu 14.04 with node.js 4.4.2 (LTS) :
The installation of strongloop was done without any errors but slc was not added to the PATH. I solved this problem by adding the symlink:
sudo ln -s /usr/local/lib/node_modules/strongloop/bin/slc.js /usr/bin/slc
Actually i am not sure my case matches with yours but i want to share my experience. i got the same message anyway.
I realized that i had changed prefix of global packets before. Then i checked prefix with the following command.
$ npm config get prefix
/home/myUser/.node_modules_global
Then i added the path to PATH variable (but .profile, .bash_profile files will be better) in active command line window and problem solved.

Why isn't Node Version Manager (NVM) recognized on Windows?

I am trying to downgrade my version of node
I ran:
npm install nvm
and I exported the bin folder to my Windows path variable,
C:\Program Files (x86)\nodejs\node_modules\npm\bin
but I still get:
'nvm' is not recognized as a an internal or external command.
Should I be adding another path to my path variable?
nvm was designed for Linux. nvmw, which is completely different, broke around node v0.10.30. Try NVM for Windows.
NVM can be used to manage various node version :
Step1: Download
NVM for Windows
Step2: Choose nvm-setup.zip
Step3: Unzip & click on installer.
Step4: Check if nvm properly installed, In new command prompt type nvm
Step5: Install node js using nvm :
nvm install <version> : The version can be a node.js version or "latest" for the latest stable version
Step6: check node version - node -v
Step7(Optional)If you want to install another version of node js - Use STEP 5 with different version.
Step8: Check list node js version - nvm list
Step9: If you want to use specific node version do - nvm use <version>
NVM Installation & usage on Windows
Below are the steps for NVM Installation on Windows:
NVM stands for node version manager, which will help to switch between node versions while also allowing to work with multiple npm versions.
Install nvm setup.
Use command nvm list to check list of installed node versions.
Example: Type nvm use 6.9.3 to switch versions.
For more info
As an node manager alternative you can use Volta from LinkedIn.
I created a universal nvm that works on both Unix (bash) and Windows, base on another simple nvm.
It doesn't need admin on Windows, but requires PowerShell 4+ and the right to execute scripts.
https://www.npmjs.com/package/#jchip/nvm#installation
The first thing that we need to do is install NVM.
Uninstall existing version of node since we won’t be using it anymore
Delete any existing nodejs installation directories. e.g. “C:\Program Files\nodejs”) that might remain. NVM’s generated symlink will not overwrite an existing (even empty) installation directory.
Delete the npm install directory at C:\Users[Your User]\AppData\Roaming\npm
We are now ready to install nvm. Download the installer from https://github.com/coreybutler/nvm/releases
To upgrade, run the new installer. It will safely overwrite the files it needs to update without touching your node.js installations. Make sure you use the same installation and symlink folder. If you originally installed to the default locations, you just need to click “next” on each window until it finishes.
Credits
Directly copied from : https://digitaldrummerj.me/windows-running-multiple-versions-of-node/
I will list two ways. You can choose one Whichever works for you.
1. Using installer
Download nvm-setup.zip and unzip the file and install it, keeping the configurations default.
1. Use curl
Copy the below command and run it in your terminal
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
After this reopen/open terminal and check the nvm version runing below command.
nvm -v
And that's it.
If someone is looking for install on Window 11! Not directly relevant here, but might be useful.
It is immaterial if you install NVM (version 1.1.9.) say after the node (16.15.1) is already installed. During the nvm installation process, it asks for the right to manage the existing node version and symlinks that.
Get the version from the GitHub repo, I opted for the zip version.
https://github.com/coreybutler/nvm-windows/releases
Double click the application and it is just a few steps.
1.downlad nvm
2.install chocolatey
3.change C:\Program Files\node to C:\Program Files\nodejsx
emphasized textThe first thing that we need to do is install NVM.
website :
https://learn.microsoft.com/en-us/windows/nodejs/setup-on-windows
So this answer is for windows users that are using git bash or some other console emulator like cmder ... if you're using CMD this solution will not work for you also why? why are you still using CMD?
I know this is a pretty old post but I just achieved this yesterday and wanted to add my answer for anyone looking to do the same.
First check if you have .bashrc profile in your home directory by typing ls -alh ~ (by default this doesn't exist)
if it doesn't exist type this command to generate a .bashrc profile with default values in it cat /etc/bash.bashrc > ~/.bashrc (if it does exist skip this step)
Download and run the nvm install script as provided in the nvm docs page curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash (make sure you do this in your home directory)
then edit the new generated .bashrc profile file you created above; use nano/vim to do that nano ~/.bashrc and add the following to the bottom of the file export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm and save your .bashrc file with the changes.
lastly source your .bashrc file by typing source ~/.bashrc
verify installation nvm --version
and now you have nvm installed and you can use the commands as per https://github.com/nvm-sh/nvm#usage
First off, I use nvm on linux machine.
When looking at the documentation for nvm at https://www.npmjs.org/package/nvm, it recommendations that you install nvm globally using the -g switch.
npm install -g nvm
Also there is a . in the path variable that they recommend.
export PATH=./node_modules/.bin:$PATH
so maybe your path should be
C:\Program Files (x86)\nodejs\node_modules\npm\\.bin
An alternative to nvm-windows, which is mentioned in other answers would be Nodist.
I've had some issues with nvm-windows and admin privileges, which Nodist doesn't seem to have.
I know I'm late here but this may help in the future if someone looking for NVM to install in Windows or linux
run this command in cmd
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash

Resources