Node.js on Ubuntu
Node.js is sort of standard for scaling backend functionalities. Within the case of Ubuntu, there are a number of sources to seize Node.js. Numerous strategies will set up completely different variations of Node.js. You too can manually choose which one to go for.
Use the tactic that fits your wants one of the best.
Set up Node.js from Ubuntu repos
That is the default methodology of putting in Node.js on Ubuntu. For a lot of the customers, this will likely be greater than sufficient. The one draw back is, you could not get the most recent model of Node.js.
The set up is tremendous easy. Replace the APT cache and set up Node.js together with npm (Node Package deal Supervisor).
$ sudo apt replace && sudo apt set up nodejs npm -y
Let’s run a fast take a look at to confirm the set up.
Set up Node.js from NodeSource PPA
NodeSource is a devoted PPA that provides a number of variations of Node.js. I like to recommend this methodology over different ones because it gives extra management. For superior customers, it additionally permits deciding the precise model of Node.js to put in. On the time of writing this text, NodeSource PPA hosts Node.js v10, v12, v13, and v14.
Right here, I’ll be showcasing how you can configure NodeSource PPA for Node.js v14. If you wish to set up a special model of Node.js, try the NodeSource readme for correct instruction.
First, be sure that your system has curl put in.
$ sudo apt replace && sudo apt set up curl -y
Now, run the NodeSource set up script.
$ curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash –
Voila! NodeSource PPA for Node.js v14 is efficiently configured! Set up Node.js.
$ sudo apt set up nodejs -y
Confirm the set up by checking the model of Node.js.
Set up Node.js utilizing nvm
It’s an attention-grabbing manner of putting in Node.js. The nvm (Node Model Supervisor) is a software that enables putting in and sustaining a number of variations of Node.js together with related Node packages independently. Take a look at nvm at GitHub.
To put in nvm, run both of the next instructions. Both of them will obtain the nvm set up script and run it.
$ curl -o- https://uncooked.githubusercontent.com/nvm-sh/nvm/v0.35.3/set up.sh | bash
$ wget -qO- https://uncooked.githubusercontent.com/nvm-sh/nvm/v0.35.3/set up.sh | bash
Shut and re-open the terminal. This can load nvm. In any other case, you may manually reload the bashrc file.
To confirm the set up, run the next command.
It’s time to make use of nvm. First, try the out there variations of Node.js. This can print out a protracted listing.
To put in the specified model, use the next command. On this instance, the command will set up Node.js v14.9.0.
Utilizing nvm, it’s doable to put in a launch based mostly on its aliases. For instance, run this command to put in the most recent LTS model erbium.
The next command will listing all of the put in Node.js variations.
If there are a number of variations put in, nvm permits switching to a special one. First, verify the present Node.js model.
Change the default Node.js to a special model.
As an alternative of utilizing the model quantity, utilizing the model alias additionally works.
$ node use
Check the change.
The next command will set the default model of Node.js.
$ nvm alias default
Set up Node.js from supply
As talked about earlier, Node.js is an open-source undertaking. We will seize the supply code and manually construct and use Node.js. Nonetheless, this method is strongly advisable to observe in the event you intend to make use of Node.js for manufacturing functions.
Earlier than leaping into the method, it’s essential to notice about Python. Node.js helps each Python 2 and Python 3. Node.js will use whichever one is put in. If each Python 2 and Python Three are put in, the later will likely be used. If solely Python 2 is put in, Python 2 will likely be used.
First, set up the construct dependencies. Run the next command. For Python Three customers, the python3-distutils bundle is critical.
$ sudo apt replace && sudo apt set up python python3-distutils g++ make
Now, obtain the supply code. On this instance, I’ll be compiling the Node.js v12.18.3 (contains npm 6.14.6). Obtain Node.js supply code.
$ wget https://nodejs.org/dist/v12.18.3/node-v12.18.3.tar.gz
Extract the supply code.
$ tar -xvf node-v12.18.3.tar.gz
The time has come to construct Node.js. Run the configuration script.
Begin the compilation course of. The “-j” is to run make in multithread mode. The “nproc” half is to inform the variety of out there CPU cores.
Set up Node.js.
Let’s confirm the set up. Verify the Node.js and npm model.
Utilizing Node.js
Node.js comes with a ton of options and functionalities. It’s a runtime for JavaScript. It’s as much as you to leverage JavaScript to get probably the most out of Node. Right here, I’ll be showcasing the very primary methods of utilizing Node.js.
First, seize a pattern JavaScript. The next code was grabbed from W3Schools.
$ var http = require(‘http’);
$ http.createServer(operate (req, res) {
$ res.writeHead(200, );
$ res.finish(‘Hi there World!’);
}).pay attention(8080);
Run the JavaScript code utilizing Node.js.
To get the output, entry your laptop from port 8080.
Closing thought
Node.js is a robust and standard resolution. There are a number of approaches to put in it on Ubuntu. Your circumstance will dictate which methodology fits you one of the best. Whereas utilizing the default Node.js from Ubuntu repo gives the best resolution, NodeSource and nvm gives extra flexibility.
As for utilizing Node.js, there are tons of supplies on-line that teaches how you can make the most of varied Node options in your JavaScript codes. W3Schools is an efficient place to begin your journey.
Comfortable computing!
ubuntu install loopback,loopback lb command not found,loopback global install,lb4 command not found,loopback 4,node js development,install node linux,install node js,install node js linux mint,install node 6,how to install node via package manager,node js update,instalar node js
