Downgrading NodeJs to below version using `n` package Not Working? - node.js

I have a virtual machine running Bitnami and my current Nodejs version is v9.8.0 but i wanted to change my version to 8.11.1 and to do that i used n npm package but still the version of NodeJs is same.
I used below commands
sudo npm cache clean -f
sudo npm install -g n
sudo n 8.11.1
Can anyone please help me.

Bitnami Engineer here.
Bitnami Stacks are completely self-contained and run independently of the rest of the software or libraries installed on your system. This means that you don't have to worry about installing any other software on your system to make the new application work. They also won't interfere with any software already installed on your system, so everything you're already running will continue to work normally.
In this case, the PATH environment variable is configured to use the Bitnami binaries before the system's ones
PATH=/opt/bitnami/redis/bin:/opt/bitnami/python/bin:/opt/bitnami/nodejs/bin:/opt/bitnami/git/bin:/opt/bitnami/apache2/bin:/opt/bitnami/common/bin:/opt/bitnami/redis/bin:/opt/bitnami/python/bin:/opt/bitnami/nodejs/bin:/opt/bitnami/git/bin:/opt/bitnami/apache2/bin:/opt/bitnami/common/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
In case you try to find all the node binaries in the system
bitnami#bitnami-nodejs-dm-1072:~$ which -a node
/opt/bitnami/nodejs/bin/node
/opt/bitnami/nodejs/bin/node
/usr/local/bin/node
The first 2 "node" is the Bitnami's ones, the 3rd one is the system's one. If you use it, you will have the new Node.js version that you installed
bitnami#bitnami-nodejs-dm-1072:~$ /usr/local/bin/node --version
v8.11.1

Related

Updating to stable version of nodejs with n

this is my first time trying to update the nodejs version of a unix server. I want to use it to create a react app, and facing the following:
>npx create-react-app test
You are running Node 8.11.3.
Create React App requires Node 10 or higher.
Please update your version of Node.
So I have tried to update the version with the following commands:
>sudo npm cache clean -f
>sudo npm install -g n
>sudo n stable
installed : v14.15.4 to /usr/local/bin/node
active : v8.11.3 at /bin/node
However it seems that didn't upgrade the version, it installed a different version in a different path.
I am not sure if it is possible just to upgrade the version that is already active, I prefer not to do a workaround and just upgrade it directly.
As complementary information if I run n doctor I see the following:
>n doctor
Checking n install destination is in PATH...
'/usr/local/bin' is not in PATH
As I said previously, what I am looking for is a safe way to update the version already installed to be able to use create-react-app, being able to rollback to previous version easily if something doesn't work, I understand that the way is using n.
Thanks in advance.
I suggest you add /usr/local/bin to the start of your PATH (so it comes before /bin).
I do not recommend you try and overwrite /bin/node using n. Something else installed /bin/node in a system directory, and overwriting it using n could leave things in a mixed and confused state. n installs to /usr/local by default, but you can set N_PREFIX to install to your home folder, for example.
To avoid confusion with having two versions of node installed, you may wish to uninstall the /bin version, likely installed by your platform package manager.
Tip: Changing where node and npm are installed is likely to change where your global npm packages are installed. I suggest you list what you have installed now in case you want to reinstall then in the "new" location. npm list -g --depth=0

How Can Knex (or Any NPM Package) Run a Different Version of Node?

I'm trying to use Knex's seed:run command (ie. npx knex seed:run), and inside my seed file I've added this line, which logs the version of Node that it's being run with:
console.log(process.version);
Now, if I run that exact same line of code in the Node command prompt itself (node), I get:
v14.2.0
Similarly, when I run node --version it correctly returns v14.2.0.
However, when Knex runs my seed file, I instead see:
v11.15.0
Can anyone explain how/why Knex is using a different version of Node, and how I can make it stop?
P.S. I've tried wiping my node_modules folder out and re-installing via npm i, but Knex continues to use an old Node somehow. Knex itself is installed at the latest version (0.21.1).
This may happen if you have a global installation that runs in privileged account (root), and a local installation to current user.
It is possible you are using some node versioning tool to manage nodejs versions, it creates a symbolic link to a managed version of node that overrides the default configuration. There are many tools that does that like nvm, n.
Danizavtz's answer didn't solve thigns for me, but it did point me in the right direction. I realized that I did have two versions of Node: one installed by Linux (using apt-get), and one I'd installed myself (to get a newer version of Node).
The solution for me was to remove the system version of Node with:
sudo apt-get remove node
That left me with a working Node ... but it removed my npm. I guess I could have just re-installed everything, but since I already had node and just needed npm, I downloaded the latest Node installation and used the node in it to install npm. I did this both with and without sudo (I'm not sure if doing it without sudo was even necessary, as it didn't fix things):
sudo ~/node-v14.3.0-linux-x64/bin/node ~/node-v14.3.0-linux-x64/bin/npm i -g npm
After that I finally got the expected Node version when I ran npx/npm!

What are the differences between node.js and node?

I've installed node.js in my machine (linux mint 15), when I run node example.js, it says:
The program 'node' can be found in the following packages:
* node
* nodejs-legacy
Try: sudo apt-get install <selected package>
So what are the differences between node and nodejs? I had both node.js and node installed previously, but when I run node example.js, the web server doesn't start at all. So I deleted node and kept node.js.
The package node is not related to node.js.
nodejs is what you want, however it is arguably better to have the command be called node for compatibility with scripts that use #!/usr/bin/env node.
You can either just create a symlink in your path:
sudo ln -s `which nodejs` /usr/local/bin/node
Or you could install nvm and then use it to install the latest version of node.js:
nvm install stable
I prefer the nvm method, as it allows you to sudo apt-get remove nodejs, and then manage which version of node you're using yourself. You can also have multiple versions of node.js installed and use nvm use <version> to easily switch between them.
I also like to add a line to the bottom my .bashrc like: nvm use stable > /dev/null. That will automatically use the latest version you have installed.
To update your node version to the latest stable: nvm install stable. Every time you do this you will need to install any npm packages that you had installed globally if you want to continue using them.
To switch to an old version just run nvm use <version>, or, if you don't have the old version installed already: nvm install <version>.
This answer is just to tell you the difference between node and nodejs packages on Debian OS.
node
Amateur Packet Radio Node program.
Package details link: https://packages.debian.org/source/wheezy/node
nodejs
Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.
Package details link:
https://packages.debian.org/source/sid/nodejs
There is a simple answer.
Node.JS is the script/code
Node compiles and runs the Node.JS

Where does node.js put its files?

I have recently started playing with node.js, but I got lost in a big mess of different versions of node, npm, nvm and other packages. I don't know what is installed globally and what is installed locally (and if locally, how do the packages know which versions of node they can use?).
I'd like to have some summary of what different installation options do. In specific:
Where is node installed when I use nvm, apt-get, make install or when using other ways?
Is it a good idea to install node locally?
Why does nvm change my ~/.profile instead of installing itself in some system-recognizable bin folder?
I saw that nvm can install different versions of node alongside each other - why would I want to do this? I can install them locally instead, right?
Where does npm install packages? I saw that it checks packages aganist version of Node, what happens to these packages when node is upgraded?
In what cases it is better to use global or local installation? Where should I put my packages then (and where they put by default?)
What's the difference between npm, nvm and nave?
EDIT: There is a lot of ways to install node here, this makes me even more confused...
Where is node installed when I use nvm, apt-get, make install or when
using other ways?
apt-get installs all the software, not only node, on the file system following the Ubuntu convention where to store binaries, man files, shared files, logs, etc. However, using apt-get you'll have only the certain version of node which is determined by the distribution release cycle. If there are updates available they will be installed with apt-get update; apt-get upgrade However, the newest version of some app won't be available until it makes its way into the distribution. For example node v0.x.y might not be available until Ubuntu 13.10 the only way to get will be to install it manually. The good side of apt-get or other system package manager is that it manages updates and package removal for you. It stores all the data about the software package in it's own database. You can always delete the node with apt-get remove node and that's it.
make install install the package manually, but it is considered harmful. Never use the make install mainly because you won't be able to delete the package easily, you'll have to read the Makefile and manually delete all the files installed by it. In a situation where you want to use make install there is always checkinstall available. It's a software which creates a native package and registers it with the system. When you decide to delete the package you could do this with one command instead of many. wiki link; Ubuntu guide on checkinstall
Now nvm script is a node version manager. It is very helpful and easy to use. It allows you to have multiple versions of node to be installed and used in parallel on your machine. It doesn't compile the node from source like make install so it is very fast. it doesn't depend on your distribution release cycle so you have access to all the node versions available at the moment. nvm downloads precompiled binaries and is perfect for general use. It stores it's node files in it's own folder locally so in case you want to compare something between the different node versions it's easy to do.
Is it a good idea to install node locally?
If by locally you mean using nvm then it's very good for development, and testing. Not sure about production performance implications and benefits between having it's installed from source or using the nvm precompiled binaries. I use nvm for development and installed from source in production. However if someone could explain this issue any further I'll be glad to learn more.
Why does nvm change my ~/.profile instead of installing itself in some system-recognizable bin folder?
Because nvm isn't an executable. It is a set of bash functions which are sourced by shell and could be used separately. You can invoke nvm_ls and nvm_ls_remote and others without the main script after is is sourced into your shell. What the main script does it parses the command line arguments and pretty prints the output in case of for example `nvm_ls_remote'.
in the ~/.profile the following line is added
[[ -s /home/USERNAME/.nvm/nvm.sh ]] && . /home/USERANME/.nvm/nvm.sh # This loads NVM
loads all the functions into your shell
I saw that nvm can install different versions of node alongside each other - why would I want to do this? I can install them locally instead, right?
You can install them locally using make install or checkinstall but you will have to make aliases for them like node_0.8.1, node_0.8.2, node_0.10.1 , etc. AND you'll have to manage new aliases, installing all the packages, removing them in case you don't need them YOURSELF. These are a tedious and boring tasks which could be error prone sometimes. nvm does all of these tasks for you for free.
You want to do this to test your app under the different versions of node. For example you are good and tested under the v0.8 but you want to use the new features of the v0.10.3 how do you do that ? You have to download the source code, compile, make an alias and run your app. you could do this with just nvm install 0.10.3 and run your app.
Sometimes you have to support more than one version of node. For example some hosted environments are not keeping in touch with the latest release and only have v0.6 Your clients which use your server app might encounter a bug specific to this version. When you fix the bug you have to reproduce it first. Using nvm installation of the v0.6 is one line and half a minute. And you can check all the versions you want this way easily. Test your code under different versions and make sure you are good to go.
Where does npm install packages? I saw that it checks packages aganist version of Node, what happens to these packages when node is upgraded?
If you are using nvm the packages which are installed globally with -g option are tied to the relevant node version. When you switch between versions with nvm use 0.x you have to either install the packages again or use nvm copy-packages <version> to use the packages from in the current version. If the packages are installed locally then it depends. package.json should contain info on the dependencies of the app. If it says node: '0.8' and you just updated to 0.9 you might encounter troubles. For example the behavior of process.nextTick was changed in the latest releases compared to 0.6. So be careful.
In what cases it is better to use global or local installation? Where should I put my packages then (and where they put by default?)
It depends. For development nvm is superior in my opinion. For me it is convenient and simple. For production there are might be some performance implications when using the precompiled binary files not optimized for your system. It would be better to ask this as a separate question so the people with the relevant experience could answer.
What's the difference between npm, nvm and nave?
npm is a node package manager -> link It contains userland packages developed by other people. These packages are not part of the node core. npm is used for publishing your code and dependency management. If your app requires other app developed by other people it is convenient to publish it via npm.
nvm is a node version manager it does a completely separate thing. It gives you an ability to very easily switch between node versions on the same machine and manages all he changes in your $PATH environment variable.
Consider nvm as update manager for the Operation System and npm as a manager of the applications for this system. Well, this comparison isn't precise but just came upon my mind
nave is basically the same as nvm but it is an executable whereas nvm is a script which is sourced into the shell. Each system has it's own benefits. You could make a separate question regarding it's use cases and differences.
My answer isn't 100% complete and contains a lot of subjective personal opinions. However, I hope I'll at least make some points more clear so you might proceed with other more specific questions. Btw, this question list of yours could be asked as separate questions. I believe stackoverflow gives best results when specific questions are asked separately and more people with relevant experience could contribute.
If you run
npm install
in folder with package.json, it installs all packages localy (in the current folder).
Also, npm default install packeges local. To install it globaly - use -g flag:
npm install -g <package>
Execute next command:
npm config list
You see all npm config description.
You can install modules in the local context of your application with
npm install modulename
In this case the module will be installed to your node_modules folder of your application.
Otherwise you can install a module in the global context with
npm install -g modulename
In this case the module will be installed for the hole system environment usually at /usr/local/bin/modulename.
The global installation makes sense for modules you need in more than one application, like express or node-inspector.

Should I install node.js on Ubuntu using package manager or from source?

Does anyone know if installing the latest build from source is a risky route to take? Should i just stick with the package manager?
Current recommendations
Use install-node-on-linux if you want a really simple install with your user account (disclaimer: I'm the author).
Use nvm if you want to install with your user account + you need to regularly switch between versions, and you're cool with a little bit of tool and environment complexity.
Follow the directions here to install via the NodeSource PPA. This is easy to do but it's the least flexible.
Old Answer
Note: At the time of this writing I'm using Ubuntu 12.10.
There are a lot of ways to install node. I personally prefer to download the source of the latest stable build and just install it to ~/local (you do this by adding --prefix to the ./configure command as seen here. There really isn't any 'risk' in doing this as everything gets installed in a directory which is separated from the rest of your system. You can have a look at the node recipe in my system install scripts here. I regularly run my update_node.py script to upgrade my installation to the latest version.
Alternatively you can follow the directions here to install the latest stable version via the package manager. I haven't actually done that so I can't comment on how well it works.
What I wouldn't do is install node from the ubuntu universe packages. You'll end up with a very dated version (currently 0.6.19).
update 1/26/2013:
If you are interested in installing node with your user (non-root) account, I highly recommend reading this blog post. I skipped the ~/.npmrc step, but found that the ~/.node_modules symlink step was critial for getting require to work properly.
update 12/30/2014:
I have migrated to using linux mint and doing binary node installs. If you have any interest in writing your own installation scripts, you can find my current one here. Specifically have a look at what I'm doing in node.sh. The execute function is run during the first install so it does things like configure the paths in .bashrc. The install function is run by update-node.sh and is used to remove an existing installation and add a new one (the latest version or one specified by the user).
update 1/8/2016:
I just switched over to using nvm. Simply install the script and then run nvm install node to get the latest version. This seems like an excellent way to get node installed with your user account.
another option is nvm (Node Version Manager) : https://github.com/creationix/nvm
bonus that it lets you easily switch between versions.
Although I live in an .rpm, and not .deb realm, fpm can do both (needs Ruby installed). I have been able to package node.js from the latest stable source without any major difficulties. In your case, the following scenario may help:
./configure --prefix=/usr
make
mkdir -p /tmp/nodejs
make install DESTDIR=/tmp/nodejs
fpm -s dir -t deb -n nodejs -v 0.8.15 -p nodejs-0.8.15.deb -C /tmp/nodejs usr

Resources