How to update npm in windows? - javascript

I am looking for a way to upgrade my npm, I follow the option 3 for windows in here npm docs. but when I install it it said npm.exe already in nodejs folder. I try to overwrite it with --force but it still not overwritten. How to do it correctly? also how to update node?

This is the new best way to upgrade npm on Windows.
Run PowerShell as Administrator
Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
npm install -g npm-windows-upgrade
npm-windows-upgrade
Note: Do not run npm i -g npm. Instead, use npm-windows-upgrade to update npm going forward. Also if you run the NodeJS installer, it will replace the node version.
Upgrades npm in-place, where node installed it.
Easy updating, update to the latest by running npm-windows-upgrade -p -v latest.
Does not modify the default path.
Does not change the default global package location.
Allows easy upgrades and downgrades.
Officially recommended by the NPM team.
A list of versions matched between NPM and NODE (https://nodejs.org/en/download/releases/) - but you will need to download NODE INSTALLER and run that to update node (https://nodejs.org/en/)

There is a tool, nvm, that solves your problem quite easly. There is also a Windows version, is not as cool as the linux/mac version but it works fine anyway

I suggest using option 1. Go to environment system variables and add "%appdata%\npm" to path like this: edit path
Then updated npm files should be loaded before those you installed with node

Node.js v16 or higher?
npm install -g npm
Node.js v14 or below?
Consider updating to latest LTS release of Node.js
npm-windows-upgrade

Related

What is difference between npm install and meteor npm install

I am working on Meteor and want to know that what is the difference between
npm install and meteor npm install.
Thanks
According to Meteor Development Group's comments in the official forum, the difference is as follows;
meteor npm calls the bundled npm version, so it doesn’t require npm to be installed globally, That is just a convenience however, so if you do have npm installed using that will work perfectly fine. That being said, it is a good practice to get into always using meteor npm, as that way you can make sure you’re using the same npm version that has been tested with your current version of Meteor.
When using meteor npm you can make sure that you are using the same npm version that has been tested with your current Meteor's version.
When using npm install it just uses the global npm on your machine. So i'd advise to use meteor npm
This may help you to understand difference between npm install and meteor npm install
The former is installing npm packages, which will be listed in packages.json and located in the node modules directory and need to be imported into your code.
The latter is using atmosphere packages which will be listed under .meteor/packages and will be included in your build (no need to import).

electron js with python 3.6, print error on npm start, downgrade python?

this is my first electron js installation, and I had to download and install its electron, NPM install (in the folder electron), but when at the start, failed.
error on print, or if I had to do python downgrade?
My error screenshot:
Make sure that you are writing python3 style code. Like when you write print It should be print(...)
I had a similar problem when installing on windows. Possible solutions:
First check the versions od npm and node, update it with this commands:
curl --silent --location https://rpm.nodesource.com/setup_6.x | bash
Install again node:
sudo apt-get install nodejs
And update:
npm update -g
If it doesn't work try to update or reinstall Phyton an put it in global environment variables path.
Check the electron git and try to download the last version manually.
Other solutions:
Install or reinstall Windows .Net.
Install or reinstall Visual Basic c++
Update the package dependencies of the node

Installing multiple npm versions

Is it possible to install multiple versions of npm for different projects that I am working on or are the npm installations always global? (Windows 10)
Are also tried installing different versions with https://github.com/marcelklehr/nodist but it seems to affect only the node version, not the npm version.
Or does npm version actually matter? Can I just use the newest npm version even when a project says the requirement is a certain npm version?
You can install multiple versions of npm by installing multiple versions of node. To do this, you can use nvm-windows. Each different installation of node installs a different version of npm
To use a different version of node and nvm in a project, you simple need to switch:
nvm use 5.0
You can also create a .nvmrc file containing the version number in the project root directory. nvm will use the specified version of node for that project.
You also can install npm using npm
Example of installing specific version:
npm i -g npm#3.5.4
If you need to use a different version of npm for each project, there are a number of possible solutions. Probably the lightest-weight version is to use npx. A semi-common use-case for this can be projects that use lock-file v1 and another that uses lock-file v2. v2 was introduced in npm v7.
So in your project using lockfile v1, if you need to install a new package.
npx npm#v6 install dalle-node
For lockfile v2, or to just use the latest and great.
npx npm#latest install dalle-node
Or does npm version actually matter?
In most cases, it's not likely to matter much. The above example is one I run in to in my own projects. If you use a project and some of the npm commands are giving you trouble, e.g. npm run, try using the version of npm the project recommends before filing a bug with the maintainer.
if you are using eclipse IDE for Node projects, you can easily change Node version using Webclipse plugin.

browserify error /usr/bin/env: node: No such file or directory

I installed node js and npm via apt-get install and all of the dependencies, then I installed browserify
npm install browserify -g
it goes through the process and it seems like it installed correctly, but when I try to do a simple bundle per this walkthrough
I get the error:
/usr/bin/env: node: No such file or directory
Some linux distributions install nodejs not as "node" executable but as "nodejs".
In this case you have to manually link to "node" as many packages are programmed after the "node" binary. Something similar also occurs with "python2" not linked to "python".
In this case you can do an easy symlink. For linux distributions which install package binaries to /usr/bin you can do
ln -s /usr/bin/nodejs /usr/bin/node
New Answer:
Uninstall any nodejs package you've installed via your system package manager (dnf, apt-get, etc), delete any silly symlinks you've been recreating every upgrade (lol).
Install NVM,
use nvm to install nodejs: nvm install 6
Old Answer:
Any talk of creating symlinks or installing some other node-package are spurious and not sustainable.
The correct way to solve this is to :
simple install the nodejs package with apt-get like you already have
use update-alternatives to indicate your nodejs binary is responsible for #!/usr/bin/env node
Like so :
sudo apt-get install nodejs
sudo update-alternatives --install /usr/bin/node nodejs /usr/bin/nodejs 100
This now becomes sustainable throughout package upgrades, dist-upgrades and so forth.
Run apt-get install nodejs-legacy.
Certain linux distributions have changed node.js binary name making it uncompatible with a lot of node.js packages. Package nodejs-legacy provides a symlink to resolve this.
You can also install Nodejs using NVM or Nodejs Version Manager. There are a lot of benefits to using a version manager. One of them being you don't have to worry about this issue.
Instructions:
sudo apt-get update
sudo apt-get install build-essential libssl-dev
Once the prerequisite packages are installed, you can pull down the nvm installation script from the project's GitHub page. The version number may be different, but in general, you can download and install it with the following syntax:
curl https://raw.githubusercontent.com/creationix/nvm/v0.16.1/install.sh | sh
This will download the script and run it. It will install the software into a subdirectory of your home directory at ~/.nvm. It will also add the necessary lines to your ~/.profile file to use the file.
To gain access to the nvm functionality, you'll need to log out and log back in again, or you can source the ~/.profile file so that your current session knows about the changes:
source ~/.profile
Now that you have nvm installed, you can install isolated Node.js versions.
To find out the versions of Node.js that are available for installation, you can type:
nvm ls-remote
. . .
v0.11.10
v0.11.11
v0.11.12
v0.11.13
v0.11.14
As you can see, the newest version at the time of this writing is v0.11.14. You can install that by typing:
nvm install 0.11.14
Usually, nvm will switch to use the most recently installed version. You can explicitly tell nvm to use the version we just downloaded by typing:
nvm use 0.11.14
When you install Node.js using nvm, the executable is called node. You can see the version currently being used by the shell by typing:
node -v
The comeplete tutorial can be found here
sudo apt-get install nodejs-legacy
This creates the symlink /usr/bin/node -> nodejs.
Source: https://lists.debian.org/debian-devel-announce/2012/07/msg00002.html
I seem the same problem when I build atom in Linux.
sudo apt-get install nodejs-dev
Fix my question.hope helpful to you.
If you don't want to symlink you could do this.
works in ubuntu
#!/usr/local/bin/node --harmony
harmony tag is for the new ECMAscript harmony
run the command which node the result will be something
/home/moh/.nvm/versions/node/v8.9.4/bin/node
Copy the path that you have got above then run the command in step 3.
ln -s /home/moh/.nvm/versions/node/v8.9.4/bin/node /usr/bin/node
You have to call "nodejs" and not "node". To verify this, type node -v on the shell: if nothing is found try nodejs -v. If that displays a version number, then the command you should be using is nodejs and not node. Therefore, you have to change the call to browserify in your script from node to nodejs (as shown below): replace
#!/usr/bin/env node
with
#!/usr/bin/env nodejs
You might also have to open the script as the superuser.

ender.js install fails

I'm trying to install ender.js.
I've run the following command
sudo npm install ender -g
but after the install (with no error), I can't access ender command line.
I have the latest node and npm install (via brew)
anybody ran into this problem?
you just need to add /usr/local/share/npm/bin to your path.
Try adding the following line to your bash profile (in ~/.profile, or ~/.bashrc, etc.):
PATH=$PATH:/usr/local/share/npm/bin
Then source the file to your current environment with . ~/.profile. And that should fix your issue.
Going forward, I would recommend using nvm to manage your node versions, and npm installs.

Categories