Whats the best way to install nodejs in different location - windows

By default nodejs is installed in /usr/local/bin/node but this location needs root access rights.
If I then install a global package like grunt-cli or a yeoman generator they also need root access rights. But I don't want to install all global packages with sudo.
So I tought why not install node and its global packages under something like opt/bin/node for example and give this location user access rights.
I used to download the installer from the nodejs website but with that I can't change location of the installation. So the question is:
How can I install nodejs in a differnt location than the default location on OSX and Windows?

Search engines are your friend.
Taken directly from the node docs:
On Windows
The http://nodejs.org/dist/latest/ directory contains executables of
the last version of Node.js engine (the engine only, i.e. without
npm):
32bit version: http://nodejs.org/dist/latest/node.exe
64bit version: http://nodejs.org/dist/latest/x64/node.exe
The http://nodejs.org/dist/npm/ directory contains the latest .zip
archive of npm (such as npm-1.1.16.zip when npm v1.1.16 was the
latest).
Manual installation steps:
Make a clean directory and add that directory to your system's PATH variable.
Download the latest node.exe to that directory.
Download the latest npm's .zip file and unpack its contents to the same directory.
Then, with the usual help of PATH, you'll be able to run scripts (node
scriptname.js) and install modules (npm install modulename) in any
directory.
...and just below that...
Installing on Mac
The http://nodejs.org/dist/latest/ directory contains the latest .pkg
package (such as node-v0.6.15.pkg when Node v0.6.15 was the latest).

we have discussed your issue with some unix guru´s.
in UNIX / MAC:
we believe the best way to install a node package "global" (non-project-specific respectively in your user environment) is to install node in folder
/opt/node or /home/user/.node and change the user-right, as you mentioned.
we believe its the wrong way, to change the /usr/ folder-rights or install global-packages with sudo.
in my case, i think the solution to change npm-config (mentioned in many other stackoverflow topics) did not changed anything, because node is still installed in /usr/bin.
still we belief, as a developer its more recommended to build such frequently updated applications like node by yourself instead of using the unix package manager. because mostly the resources ain't up to date.

I've had great success with nvm: https://github.com/creationix/nvm. It's a version manager for node, but one of the best parts of it (for me) is that it installs each version of node in your home directory. This means that your npm global install is also in this home directory. It's a Mac/Unix solution.
For Windows, though I've never tried it, there is the (similar) nvmw project: https://github.com/hakobera/nvmw.

Related

Why is poetry only available from the .poetry\bin directory?

I installed poetry to windows using get-poetry.py. I cloned the entire poetry-master folder from the github to my desktop, unzipped it, then ran the install file. It asked me if I would like to modify something but responding both yes and no didn’t allow me to input any addiditonal information. The .poetry file ended up in my user directory. (Ex: C:\Users\CursedDog19\ .poetry)
I need poetry to install a package from GitHub for testing but my install of poetry only runs from one directory (\ .poetry\bin) Poetry claims to run from all directories.

I'm trying to clean up my usr/local folder in OSX 10.13

OSX (Darwin 17.6.0) Node (v0.12.2) and NPM (v 2.7.4) are installed.
I'm not sure if I used Homebrew to install anything (because there's 'Cellar' folder), but I've deleted Hombrew.
I've been trolling through stack overflow for hours (being new to this) trying to remove old/not used files. I think I might have installed things using 'sudo' (whups). Why I think this: NPM gives me a bunch of ERR! and code EACCES errno -13.
What files and folders in the local/bin, local/Cellar, and local/lib, man files etc... can I manually delete to get to back to ground zero? I'm pretty sure that I wont be using bower, claymate, gulp, grunt, or yo. Lord know why I installed them....
Or do I sudo update/upgrade/uninstall something, or root update/upgrade/uninstall something? I'm not positive about the differences.
According to the Homebrew Documentation FAQ:
Apple has assigned this directory [/usr/local] for non-system utilities. Which means there is no files in /usr/local by default, so there is no need to worry about messing up existing or system tools.
This means that you can run:
sudo rm -rf /usr/local/*
whithout breaking any system level tools or libraries. Then reinstall any third party tool you need.

Conda environment from .yaml offline

I would like to create a Conda environment from a .yaml file on an offline machine (i.e. no Internet access). On an online machine this works perfectly fine:
conda env create -f environment.yaml
However, it doesn't work on an offline machine as the packages are then not found. How do I do this?
If that's not possible is there another easy way to get my complete Conda environment to an offline machine (including both Conda and pip installed packages)?
Going through the packages one by one to install them from the .tar.bz2 files works, but it is quite cumbersome, so I would like to avoid that.
If you can use pip to install the packages, you should take a look at devpi, particutlarily its server. devpi can cache packages normally installed from PyPI, so only on first install it actually retrieves them. You have to configure pip to retrieve the packages from the devpi server.
As you don't want to list all the packages and their dependencies by hand you should, on a machine connected to the internet:
install the devpi server (I have that running in a Docker container)
run your installation
examine the devpi repository and gathered all the .tar.bz2 and .whl files out of there (you might be able to tar the whole thing)
On the non-connected machine:
Install the devpi server and client
use the devpi client to upload all the packages you gathered (using devpi upload) to the devpi server
make sure you have pip configured to look at the devpi server
run pip, it will find all the packages on the local server.
devpi has a small learning curve, which already worth traversing because of the speed up and the ability to install private packages (i.e. not uploaded to PyPI) as a normal dependency, by just generating the package and upload it to your local devpi server.
I guess that Anthon's solution above is pretty good but just in case anybody is interested in an easy solution that worked for me:
I first created a .yaml file specifying the environment using conda env export > file.yaml. Following the instructions on http://support.esri.com/en/technical-article/000014951, I automatically downloaded all the necessary installation files for conda installed packages and created a channel from the files. For that, I just adapted the code from the link above to work with my .yaml file instead of the conda list file they used. In addition, I automatically downloaded the necessary files for the pip installed packages by looping through the pip entries in the .yaml file and using pip download for downloading each of them. Furthermore, I automatically created separate conda and pip requirement lists from the .yaml file. Then I created the environment using conda create with the offline flag, the file with the conda requirements and my custom channel. Finally, I installed the pip requirements using pip install with the pip requirements file and the folder containing the pip installation files for the option --find-links.
That worked for me. The only problem is that you can only download binaries with pip download if you need to specify a different operating system than the one you are running, and for some packages no binaries are available. That was okay for me now as the target machine has the some characteristics but might be problem in the future, so I am planning to look into the solution suggested by Anthon.

NVM for Windows not working?

I just installed NVM for Windows, but it doesn't seem to be working:
Any ideas?
First examine your actual "C:\Program Files\nodejs" directory. Most of us already have a "nodejs" directory from a prior install, before we decided (or were told) to install nvm.
In the end, this "C:\Program Files\nodejs" directory will actually be a shortcut to where nvm manages the versions it installs (see C:\Users\xxx\AppData\Roaming\nvm). It seems that nvm is simply switching the shortcut, when we call "nvm use ...".
Ok, so here is what I did to fix the situation where "nvm use ..." was not taking effect.
Delete/remove/uninstall the version of node in your "C:\Program Files\nodejs" directory. To the point where there is no more "nodejs" directory at all.
Delete the existence of nvm (C:\Users\xxx\AppData\Roaming\nvm), basically, manually delete the nvm dir.
Download your desired version of nvm (https://github.com/coreybutler/nvm-windows/releases)
Open a CMD prompt (run as administrator), and install the downloaded version of nvm, nvm-setup.exe, from within this CMD command prompt.
From within the admin level command prompt, run "nvm install 7.2.1", or whatever node version you want to install. Probably you will be installing multiple versions, so repeat as needed.
Now do the usual "nvm use ...", "nvm list", etc...
I dont know if this is the best way, but it worked for me...
Having the same issue after installing latest node with nvm. node command was not recognized in console. Closing and opening command windows did not work. checked nvm arch to which the response is
C:\WINDOWS\system32> nvm arch
System Default: 64-bit.
Currently Configured: -bit.
Had to set the node again with arch setting
C:\WINDOWS\system32> nvm use 7.4.0 x64
Now using node v7.4.0 (64-bit)
C:\WINDOWS\system32> nvm arch
System Default: 64-bit.
Currently Configured: 64-bit.
C:\WINDOWS\system32> nvm list
* 7.4.0 (Currently using 64-bit executable)
4.5.0
C:\WINDOWS\system32> node -v
v7.4.0
Rename "C:\Program Files\nodejs" to "C:\Program Files\nodejsx"
nvm use x.x.x
This worked for me. Maybe it will work for you too.
Most likely what is happening is that the system %PATH% is being updated outside of the command prompt instance. Only opening a new command prompt will pick up these new external changes.
I had the same problem in Windows 10, and the solution for me was in #pleverett answer in https://github.com/coreybutler/nvm-windows/issues/191
Symptoms: no bit architecture and no default version
C:\WINDOWS\system32> nvm arch
System Default: 64-bit.
Currently Configured: -bit.
C:\WINDOWS\system32> nvm list
8.9.4
6.13.0
Solution:
After uninstalling node, make sure the directory where node was originally installed has been removed and not just empty. For Windows 7 ad 10, 64-bit, the default is "C:\Program Files\nodejs".
If the "nodejs" directory still exists then the "nvm use" command can't make the symbolic link to the node version under nvm's control.
I had the same problem until I manually deleted the "nodejs" directory.
Make sure you delete all old nodejs.
Install nvm
Install node
Open new terminal prompt
run 'nvm on'
run 'nvm list'
run 'node --version'
In my case I was using git bash -- switching to cmd.exe worked.
More suggestions at: https://github.com/coreybutler/nvm-windows/issues/58
I had to manually set the PATH variable in System environment variables of Windows to fix this issue.
Here are the steps:
Before installing nvm, delete the following path:
C:\Program Files\nodejs
C:\Program Files (x86)\nodejs
after installing nvm execute:
nvm use
After the use command you can find a shortcut 'C:\Program Files\nodejs' is created by
nvm in this path.
The problem i found was the path 'C:\Program Files\nodejs' was not set in the windows system evnironment PATH variable.
i appended 'C:\Program Files\nodejs' to the %PATH% variable to fix this issue.
I had to open the installer with admin permissions.
Then I opened the command line and I was able to install and use nvm properly.
nvm install 10.0.0
nvm use 10.0.0
node --version
// version 10 is used.
I installed nvm-windows in order to get multiple versions of node to work. After installation I got the error that most folks complained about which is that it was unable to find the file settings.txt. There are two things required to get nvm-win to work and the installer only does the first of these two. So after installation just check that points 1 and 2 are covered and you should be good. There is no need to uninstall prior versions of node as far as i can tell.
update the system path variable to the directory where you installed nvm and where the nvm.exe is located. ex. c:\nvm
add a new variable NVM_HOME to the system variables.
open a new command window after verifying 1 and 2.
Problem 2 switching between versions
Switching between versions gives a success message but it will not actually work properly unless you manually update the windows system path variable to point to the location that you installed your target version in, for example C:\Users\adamm>nvm list
10.15.1
* 6.4.0 (Currently using 64-bit executable)
So it appears to work but if you type node -v it will show whichever version is currently in your path variable until you edit the path variable to use 6.4.0
I was getting the same issue. I installed node using nvm but 'node' and 'npm' were not recognized by the system.
So, what I did was I didn't delete any folders or anything I just ran the command prompt as administrator and did the nvm install 'desired-version' and everything started to work fine.
I understand this is an old question.
However, what fixed it for me isn't in any of the answers above, which is why I decided to answer this in case new persons find this page and none of the above answer works for them...
All I had to do was run nvm on which creates the symlink (supposedly, nvm use <version> is supposed to work, but it wasn't), turning on nvm before using a version worked for me.
Steps:
nvm install <version> -> Installs a node and npm of <version>
nvm on -> Turns on nvm, and creates the nodejs symlink needed
nvm use <version> -> To use a specific version
node -v -> prints out version of node
npm -v -> prints out version of npm
Hopefully, it fixes your issue too.
For me,
nvm list
Then I remove v8.9.4 folder out of nvm.
After that:
nvm list
Then, I move v8.9.4 back.
For me it was I installed node using nvm on a non-admin cmd.
Running cmd as admin worked for me.
open a new cmd with admin rights then run this command.
run 'nvm on'
Why isn't node version changing with nvm for windows even when nvm on ?
when nodejs is already installed, the enviroment variable NVM_SYMLINK which created when nvm for windows is installed will point to C:\Program Files\nodejs(which is default)
what is the expected behavior ?
when we run nvm on and then nvm use x.x.x, we should able to switch to the desired node version without any hassle.
how to fix ?
uninstall the nodejs using uninstall/remove programs from control panel and delete C:\Program Files\nodejs if exists
check (once) if NVM_SYMLINK in environment variables is changing automatically when running nvm use x.x.x
if not changing automatically then uninstall and reinstall nvm for windows (remove any other node remains)
Note: I am able to switch to the desired versions of node by changing the user environment variable NVM_SYMLINKto C:\Users\Charlie\AppData\Roaming\nvm\vx.x.x without uninstalling the node.
At my work we are assigned a user account and an administrative account which we use to install and manage software for our machines. NVM was installed under this admin account and therefore, none of the answers above worked for me.
I had to manually add %NVM_HOME% and %NVM_SYMLINK% to my user account's path before I could get node --version to display anything.
So if you have to deal with a regular account and an administrative account then the following will work for you:
Install NVM (which will have to be installed using your admin account)
Manually added %NVM_HOME% and %NVM_SYMLINK% to your user account's path (if you check your admin account's path you'll see these 2 were added there during the NVM installation)
nvm install latest
nvm on
nvm use x.x.x
Restart computer so your IDE recognizes the changes
$Profit$
To me the issue was that I had problems with the download, I had to download the zip file manually and place its contents int he nvm folder C:\Users\xxx\AppData\Roaming\nvm
Try nvm run node --version
You can also get the path to the executable to where it was installed:
nvm which 5.0
Something that fixed it for me: Comb through your PATH variable. I had multiple links to different node versions and it worked perfectly after I cleaned up all of them, leaving NVM's variables in tact.
If executing where node comes back with more than one path this is likely your issue.
This work fine for me:
In the C:\Program Files\ folder use cmd to run mklink /D /J nodejs C:\Users\[user]\AppData\Roaming\nvm[node version]
Please note that cmd run in administrator mode.
Detail here: https://github.com/coreybutler/nvm-windows/issues/321#issuecomment-407876718
For me, the issue was that I was using the nosetup way and downloaded the zip in my user Downloads folder. When I switched to setup installer, it worked for me.
You need Administrator access for installing node. Since you got into problem before knowing solution, follow below step.
Note down all installed node version(Optional)
"C:\Program Files\nodejs" (Optional but Recommended)
Delete "C:\Users\xxx\AppData\Roaming\nvm"
Reinstall nvm
Run cmd as Administrator
nvm install x.x.x
I had same issue. C:\Program Files\nodejs shortcut folder was present but was not pointing to anywhere.
I simply deleted the C:\Program Files\nodejs symlink and executed the below command
nvm use 0.10.36
This created new C:\Program Files\nodejs symlink and it worked properly.
Aside to all other solutions described here, there is another issue with nvm. Nvm switches between version of Node.js. Node.js builds are grabbed from Node.js repository.
If you can switch between some versions, but not all, and specifically you can not switch to versions you just grabbed, that answer is for you.
The situation happens because Node.js rebuilds old builds. For example, there is a build 10.14.1 you can grab from their repository, and that nvm grabs. But it is not a build from the past. Node.js rebuilds old builds too regularly.
Unfortunately, they don't take care about backwards compatibility. It means that if your operating system is not supported by Node.js, not only the latest build won't be supported. All old builds will also be broken for your system.
Currently, Node.js supports Windows 10+. It means that all old Node.js packages has been rebuilt in a way, that break them for Windows 8.x and Windows 7.
What is astonishing, there is no place to grab the old, working builds. Once they rebuild old releases, they break backwards compatibility.
As for now, there is no solution for that. The only thing you can do, is to grab releases while they are supported on your system. For example now, you can grab versions for Windows 10, because when they announce Windows 11 is a minimum requirement, all Node.js builds will break on Windows 10.
From the nvm perspective, you can see any kind of errors during the installation. During switching the visible result is that you can not switch between versions. The version you choose is not the current one and not marked with an asterix in the npm list result.
For me there were 2 things I needed to do:
Run nvm install as administrator
Specify the exact version (major.minor.point) with nvm use
Steps:
Open Terminal as Administrator
Run nvm install 14
Run nvm use 14.20.0
Open Terminal as non-admin
Run node -v to verify it's using 14.20.0
If I tried nvm use 14 without minor or point version, it did not work, which differs from NVM on Mac. I also could not run nvm use in a non-admin terminal, it gave "Access is denied".
For me deleting npm and npm-cache folder from AppData works
For me running nvm install 14.0.0 from PowerShell with admin rights did the job.
You must delete your C:\Program Files\nodejs directory.
Check the version of the node available with nvm list.
If you have your version, run command nvm use x.x.x.
otherwise run nvm install x.x.x and run command nvm use x.x.x.
For me setting up environment path variable also didn't work. Finally I got the cause and it was incompatible node version, once I downgraded my node from 14 to version used in my frontend application i.e. v8.11.3, it worked for me.

Installing packages in native windows node.js

I am trying to get to grips with node.js, this looked like a fun tut http://net.tutsplus.com/tutorials/javascript-ajax/how-to-scrape-web-pages-with-node-js-and-jquery/ but I have only got the native windows version of node.js and I can't find a way to install any packages.
I have also looked at installing the binaries using chocalatey, but my version of vista doesn't have access to powershell. However, I do have a machine running windows 7 that I can switch to. If it isn't possible to install packages on windows version, I will switch to that machine and work through chocalatey.
Assuming you have the node.exe for Windows, npm has experimental support for windows. You can try working through the README.
Otherwise you can manually install packages on Windows. You will need to manually look at the package.json files for dependencies if you are going with option 2.
I have never tried it, but Scott Hanselman also has a post about getting node running on Windows.
Personally I have found its easier to just run a Linux VM since Windows support is kinda spotty right now.
The short answer is if you have git properly installed, you can open a cmd window, navigate to the directory containing node.exe, and run this:
git config --system http.sslcainfo /bin/curl-ca-bundle.crt
git clone --recursive git://github.com/isaacs/npm.git
cd npm
node cli.js install npm -gf
The more complete answer is that I posted a guide on how to install Node on Windows here. It also describes installing npm to manage packages. Let me know if it works for you.

Resources