I am trying to change the version of nodejs using cmd n installed globally by yarn. Neither yarn is detected by sudo nor n.
Please help me to fix this:
When running the n command to change node version, it shows permission is denied by many files to be written by n
Two approaches to avoid permission issues without requiring use of sudo when running n:
install and run Node.js from your home folder using N_PREFIX and PATH (see also n-install which automates this)
if it is your personal computer, take ownership of the folders used with default install location of /usr/local
See the project README for more: https://github.com/tj/n
(Disclaimer: I am the maintainer of n.)
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).
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)
I have a problem understanding the use of n. Basically, it is clear that it is a version manager for Node.js such as nvm.
But in contrast to nvm, which is basically a shell script, according to the documentation you are encouraged to use npm to install n:
$ npm install -g n
What I don't get is: For having npm at hand you need to install Node.js. Why would I install Node.js manually to use npm to then be able to install Node.js using n?
To put my question in other words: Why does n suggest installing using npm, if its main purpose is to install Node.js, which includes npm?
tl; dr
# Installs n and the latest LTS Node.js version to ~/n.
# For bash, ksh, zsh, modifies the respective user-specific shell-initialization file to
# define env. variable N_PREFIX and append $N_PREFIX/bin to the $PATH.
curl -L https://git.io/n-install | bash
I feel your pain. Installing Node.js to then install n to then manage Node.js installations is indeed a strange setup.
It would indeed be great to be able to install n by itself first.
I've created a project to support installation of n directly from GitHub; the only prerequisite beyond what n itself needs is git.
Note that you must first remove any pre-existing n / Node.js versions.
The target directory, ~/n by default, must either not yet exist or be empty.
For bash, ksh, and zsh, the relevant shell initialization file (e.g., ~/.bashrc) is automatically modified to define environment variable N_PREFIX and append $N_PREFIX/bin to the $PATH; for other shells, this must be done manually.
Aside from installing n directly from GitHub, it also installs helper scripts for updating n (n-update) and uninstalling it (n-uninstall).
Here are working examples; see the n-install GitHub repo for details:
Installation with confirmation prompt to confirm installing to default location $HOME/n and installing the latest LTS Node.js version:
curl -L https://git.io/n-install | bash
Automated installation to the default location, with subsequent installation of the latest LTS (long-term support) and latest-overall Node.js versions, as well as the latest 4.1.x Node.js version:
curl -L https://git.io/n-install | bash -s -- -y lts latest 4.1
Automated installation to the default location, without subsequent installation of a Node.js version:
curl -L https://git.io/n-install | bash -s -- -y -
Automated installation to custom location ~/util/n, with subsequent installation of the latest LTS Node.js version:
curl -L https://git.io/n-install | N_PREFIX=~/util/n bash -s -- -y
If you prefer, you can install n from source:
cd /tmp
git clone --depth=1 https://github.com/tj/n
cd n
sudo make install
Then you can install the latest stable version of node as follows:
n stable
The n module was created for convenience.
For example, if you wanted to update your version of Node.js from v0.8.0 to v0.10.20, would you rather download a package, extract and compile? Or would you rather type n 0.10.20 and have it instantly installed, while still retaining previous versions of Node for easy switching?
n suggests using npm to install it because n is a module. That is, npm is the easiest way to install it. Node modules have the functionality of being able to run in a shell when installed globally, so that function was utilized to make switching Node versions much easier.
You can also install npm separately from Node.JS; e.g.: on a system without Node.JS:
git clone https://github.com/npm/npm
cd npm
./configure
make
Reference: NPM GitHub project
I had the same question, but have seen the light. 'n' is a handy tool and makes it simple to test different versions of node. Works great on Linux, but no matter how I try to install it on OS X (git clone, then npm install or using user456584's recommended method), when I run it, I always get the same results of "Error: no installed version", even though it installs into
/usr/local/lib/node_modules/n
and
/usr/local/bin/n
Frustrating because I've found this tool to be so handy on Linux.
If you have included your default node bin in the $PATH variable like this
export PATH=/usr/local/Cellar/node/11.5.0/bin:$PATH
then n will not be able to active other node versions. Remove this export from the path and then you can manage the currently active node version by n.
The README for n now has a longer section covering different installation approaches.
Like nvm, n is a bash script. npm is suggested as an easy way to install n if you already have npm, and then you can use n to change the Node.js version. But there are plenty of other approaches for a first install of Node.js. In brief and in no particular order...
You can install n using curl:
curl -L https://raw.githubusercontent.com/tj/n/master/bin/n -o n
Or clone the n repo and install from there:
make install
Or use n-install:
curl -L https://git.io/n-install | bash
Or Homebrew:
brew install n
Or MacPorts:
port install n
(Disclaimer: I am the current maintainer of n.)
If you are using n then you should use below command
bash$ sudo n latest
In *nix, when I compile software, when should I do:
# make install
vs
# make install clean
?
When you call make with arguments, you are giving it a list of targets.
There is some discussion of this in the Upgrading Ports section of the FreeBSD Handbook where it says:
Unlike the usual make install clean command, it will upgrade all
the dependencies prior to building and installing the selected
port.
[...]
Note: You can save two extra steps by just running make install
clean instead of make, make install and make clean as three
separate steps.
Also, as a side note: Don't build your package as root unless you really need to. In general you should work in an unprivileged account and then as a final step you can do sudo make install if you have to. It would be better, though, to add the unprivileged user to a group with write-access to the install directories, or even better to install it into a non-system area (for example, with ./configure you can use --prefix=) since most systems, whether Linux or BSD, usually have packages and a packaging system that is used to install software.