{"_id":"59d01d530cd4dd0010294e3f","project":"568bdc1483d2061900d86cdc","version":{"_id":"59a72290d61777001b6c42c3","project":"568bdc1483d2061900d86cdc","__v":19,"createdAt":"2017-08-30T20:39:44.453Z","releaseDate":"2017-08-30T20:39:44.453Z","categories":["59a7236e3fe4d90025117c10","59a72eb6cb0db3001b84cfe2","59a734eb757d030019b85af8","59c0243b1b2d07001a9d2b76","59c035e42126e10028effb12","59c06c40df5b3c0010584a13","59c1a5852cabe5002641a3e7","59c2fb00b2b45c0010b7a3d7","59c32ceb9aea850010ac4130","59c32e6e190c90003cb0d12f","59c33affb2b45c0010b7aa23","59c7dfa457bd8200105444dc","59c7e975c50cf30010d712a0","59cffdef0cd4dd0010294d54","59d0622ca91a810032c8f60c","59d06733c1aec60026253065","59d174d44ac471001a07b123","59d5a5e323e6e800103defb2","59ecf1d8ed507c001c52b255"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"","version_clean":"0.0.0","version":"0"},"category":{"_id":"59a72eb6cb0db3001b84cfe2","project":"568bdc1483d2061900d86cdc","version":"59a72290d61777001b6c42c3","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2017-08-30T21:31:34.201Z","from_sync":false,"order":0,"slug":"knowledge-base","title":"Getting Started"},"user":"58cc41f21751ce2f003be3b7","__v":0,"parentDoc":null,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2017-09-30T22:40:19.516Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":3,"body":"[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"x86/x64 Linux Desktop\"\n}\n[/block]\nHead over to https://nodejs.org/en/download/ to get the download url to NodeJS. For this demonstration, NodeJS (v7.2.0) will be installed on Ubuntu 16.04.1.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/ca26c74-Screenshot_from_2016-12-06_12-38-20.png\",\n        \"Screenshot from 2016-12-06 12-38-20.png\",\n        1052,\n        665,\n        \"#e7eee7\"\n      ]\n    }\n  ]\n}\n[/block]\nNext, open up **Terminal** and use `wget` to download the Linux binary.\n\n```\nwget https://nodejs.org/dist/v7.2.0/node-v7.2.0-linux-x64.tar.xz\n```\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/9b600c0-Screenshot_from_2016-12-06_12-37-28.png\",\n        \"Screenshot from 2016-12-06 12-37-28.png\",\n        746,\n        452,\n        \"#060607\"\n      ]\n    }\n  ]\n}\n[/block]\nNow use `tar` to unpack the file.\n\n```\n tar -xvf node-v7.2.0-linux-x64.tar.xz\n```\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/af7aaf2-Screenshot_from_2016-12-06_12-49-59.png\",\n        \"Screenshot from 2016-12-06 12-49-59.png\",\n        746,\n        452,\n        \"#050507\"\n      ]\n    }\n  ]\n}\n[/block]\nInstall NodeJS into `/usr/local/`.\n```\ncd node-v7.2.0-linux-x64\nsudo cp -R * /usr/local/\n```\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/28f61d9-Screenshot_from_2016-12-06_12-52-22.png\",\n        \"Screenshot from 2016-12-06 12-52-22.png\",\n        746,\n        452,\n        \"#040404\"\n      ]\n    }\n  ]\n}\n[/block]\nYou can check that NodeJS and NPM are installed correctly by confirming their version numbers from **Terminal** by running\n\n```\nnode -v\nnpm -v\n```\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/c2bfe01-Screenshot_from_2016-12-06_12-53-56.png\",\n        \"Screenshot from 2016-12-06 12-53-56.png\",\n        746,\n        452,\n        \"#040404\"\n      ]\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"ARM/Raspbery Pi\"\n}\n[/block]\nDepending on which version of Raspberry PI you are using (1,2,3, Zero, etc) you will need to download the appropriate pre-compiled binary (ArmV7, ArmV8). \n\nThese instructions will show the process for a Raspberry Pi 3 (Running 2016-05-27-raspbian-jessie-lite). \n\nDownload and unpack NodeJS (ArmV7).\n\n```\nwget https://nodejs.org/dist/v7.2.0/node-v7.2.0-linux-armv7l.tar.xz\ntar -xvf node-v7.2.0-linux-armv7l.tar.xz\n```\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/e73c493-Screen_Shot_2016-12-05_at_5.13.24_PM.png\",\n        \"Screen Shot 2016-12-05 at 5.13.24 PM.png\",\n        589,\n        450,\n        \"#efefef\"\n      ]\n    }\n  ]\n}\n[/block]\n\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/02dc561-Screen_Shot_2016-12-05_at_5.13.59_PM.png\",\n        \"Screen Shot 2016-12-05 at 5.13.59 PM.png\",\n        617,\n        478,\n        \"#ecebea\"\n      ]\n    }\n  ]\n}\n[/block]\nInstall NodeJS into `/usr/local/`.\n\n```\ncd node-v7.2.0-linux-armv7l\nsudo cp -R * /usr/local/\n```\n\nAt this point you can test Node to confirm that you have installed the correct version.\n\n\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/e277122-Screen_Shot_2016-12-05_at_5.21.47_PM.png\",\n        \"Screen Shot 2016-12-05 at 5.21.47 PM.png\",\n        617,\n        478,\n        \"#040404\"\n      ]\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"Incorrect NodeJS Version\",\n  \"body\": \"If `node -v` reports something similar to `-bash: /usr/local/bin/node: cannot execute binary file: Exec format error` or does not respond, you may have installed a version of NodeJS not compatible with your operating system architecture. You can simple repeat the install process with the correct version as it will overwrite the previously installed files.\"\n}\n[/block]\nClean up the temporary files.\n\n```\ncd ~\nrm -rf node-v7.2.0-linux-armv7l\nrm node-v7.2.0-linux-armv7l.tar.xz\n```\n\nNodeJS and NPM are now installed!\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Installing Node modules globally (Linux Desktop/ Embedded)\"\n}\n[/block]\nYou can install some npm packages globally, such as the [droplit.io CLI](https://www.npmjs.com/package/droplit-cli), to run them from any directory. \n\n```\nnpm install droplit-cli -g\n```\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/e3786b2-Screenshot_from_2016-12-06_13-15-29.png\",\n        \"Screenshot from 2016-12-06 13-15-29.png\",\n        746,\n        452,\n        \"#040404\"\n      ]\n    }\n  ]\n}\n[/block]\nHowever, you may encounter an error like this when installing npm packages globally.\n\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/7ecea56-Screenshot_from_2016-12-06_12-57-15.png\",\n        \"Screenshot from 2016-12-06 12-57-15.png\",\n        746,\n        452,\n        \"#060707\"\n      ]\n    }\n  ]\n}\n[/block]\nThere are a few ways to solve this issue according to [docs.npmjs.com](https://docs.npmjs.com/getting-started/fixing-npm-permissions). We prefer Option 2 as it does not require changing directory ownership, which may be a security risk.\n\nFirst, change the install location of global packages.\n```\nmkdir ~/.npm-global\nnpm config set prefix '~/.npm-global'\n```\n\nCreate/edit `.bashrc` to add the new directory to your `PATH`. \n\n```\necho \"export PATH=~/.npm-global/bin:\\$PATH\" >> ~/.bashrc\n```\n\nMake sure you are the owner of the `~/.npm-global/` directory, or assert your ownership using the following\n```\nchown <username>:users ~/.npm-global\n```\n\nRestart your terminal and you should be able to install and use global packages. \n[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"The `.bash_profile` is only executed for a login-shell, whereas `.bashrc` is executed for every new shell instance\",\n  \"title\": \"You can use .bash_profile instead of .bashrc if you wish.\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"MIPS/OpenWRT\"\n}\n[/block]\nIf you wish to run NodeJS on an OpenWRT device and node is not already provided for your distribution or node is provided and you require a new version, you should be familiar with [OpenWrt's build system](https://wiki.openwrt.org/about/toolchain).\n\n[This article](https://github.com/netbeast/docs/wiki/Cross-Compile-Nodejs-for-OpenWrt) explains how to cross compile NodeJS for OpenWRT. \n\nOnce you have the NodeJS Binary file, transfer it to your OpenWRT device. You may need to mark it as executable. \n\n`chmod node 755`\n\nDepending on CPU speeds, we recommend downloading npm packages on a different computer and transfer them to your device. If any of your packages require compilation, you will want to compile them with your toolchain.\n\n\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"body\": \"In our testing, we found that the OpenWRT kernel required FPU emulation be enabled for NodeJS to run.  Without FPU Emulation, we tested many different versions of NodeJS (0.10 - 6.0.0), and each would result in a floating point exception or not respond. When compiling your OS make sure that you have this feature enabled.\",\n  \"title\": \"FPU emulation\"\n}\n[/block]","excerpt":"","slug":"install-nodejs-on-linux","type":"basic","title":"NodeJS Setup: Linux/Embedded Systems"}

NodeJS Setup: Linux/Embedded Systems


[block:api-header] { "type": "basic", "title": "x86/x64 Linux Desktop" } [/block] Head over to https://nodejs.org/en/download/ to get the download url to NodeJS. For this demonstration, NodeJS (v7.2.0) will be installed on Ubuntu 16.04.1. [block:image] { "images": [ { "image": [ "https://files.readme.io/ca26c74-Screenshot_from_2016-12-06_12-38-20.png", "Screenshot from 2016-12-06 12-38-20.png", 1052, 665, "#e7eee7" ] } ] } [/block] Next, open up **Terminal** and use `wget` to download the Linux binary. ``` wget https://nodejs.org/dist/v7.2.0/node-v7.2.0-linux-x64.tar.xz ``` [block:image] { "images": [ { "image": [ "https://files.readme.io/9b600c0-Screenshot_from_2016-12-06_12-37-28.png", "Screenshot from 2016-12-06 12-37-28.png", 746, 452, "#060607" ] } ] } [/block] Now use `tar` to unpack the file. ``` tar -xvf node-v7.2.0-linux-x64.tar.xz ``` [block:image] { "images": [ { "image": [ "https://files.readme.io/af7aaf2-Screenshot_from_2016-12-06_12-49-59.png", "Screenshot from 2016-12-06 12-49-59.png", 746, 452, "#050507" ] } ] } [/block] Install NodeJS into `/usr/local/`. ``` cd node-v7.2.0-linux-x64 sudo cp -R * /usr/local/ ``` [block:image] { "images": [ { "image": [ "https://files.readme.io/28f61d9-Screenshot_from_2016-12-06_12-52-22.png", "Screenshot from 2016-12-06 12-52-22.png", 746, 452, "#040404" ] } ] } [/block] You can check that NodeJS and NPM are installed correctly by confirming their version numbers from **Terminal** by running ``` node -v npm -v ``` [block:image] { "images": [ { "image": [ "https://files.readme.io/c2bfe01-Screenshot_from_2016-12-06_12-53-56.png", "Screenshot from 2016-12-06 12-53-56.png", 746, 452, "#040404" ] } ] } [/block] [block:api-header] { "type": "basic", "title": "ARM/Raspbery Pi" } [/block] Depending on which version of Raspberry PI you are using (1,2,3, Zero, etc) you will need to download the appropriate pre-compiled binary (ArmV7, ArmV8). These instructions will show the process for a Raspberry Pi 3 (Running 2016-05-27-raspbian-jessie-lite). Download and unpack NodeJS (ArmV7). ``` wget https://nodejs.org/dist/v7.2.0/node-v7.2.0-linux-armv7l.tar.xz tar -xvf node-v7.2.0-linux-armv7l.tar.xz ``` [block:image] { "images": [ { "image": [ "https://files.readme.io/e73c493-Screen_Shot_2016-12-05_at_5.13.24_PM.png", "Screen Shot 2016-12-05 at 5.13.24 PM.png", 589, 450, "#efefef" ] } ] } [/block] [block:image] { "images": [ { "image": [ "https://files.readme.io/02dc561-Screen_Shot_2016-12-05_at_5.13.59_PM.png", "Screen Shot 2016-12-05 at 5.13.59 PM.png", 617, 478, "#ecebea" ] } ] } [/block] Install NodeJS into `/usr/local/`. ``` cd node-v7.2.0-linux-armv7l sudo cp -R * /usr/local/ ``` At this point you can test Node to confirm that you have installed the correct version. [block:image] { "images": [ { "image": [ "https://files.readme.io/e277122-Screen_Shot_2016-12-05_at_5.21.47_PM.png", "Screen Shot 2016-12-05 at 5.21.47 PM.png", 617, 478, "#040404" ] } ] } [/block] [block:callout] { "type": "warning", "title": "Incorrect NodeJS Version", "body": "If `node -v` reports something similar to `-bash: /usr/local/bin/node: cannot execute binary file: Exec format error` or does not respond, you may have installed a version of NodeJS not compatible with your operating system architecture. You can simple repeat the install process with the correct version as it will overwrite the previously installed files." } [/block] Clean up the temporary files. ``` cd ~ rm -rf node-v7.2.0-linux-armv7l rm node-v7.2.0-linux-armv7l.tar.xz ``` NodeJS and NPM are now installed! [block:api-header] { "type": "basic", "title": "Installing Node modules globally (Linux Desktop/ Embedded)" } [/block] You can install some npm packages globally, such as the [droplit.io CLI](https://www.npmjs.com/package/droplit-cli), to run them from any directory. ``` npm install droplit-cli -g ``` [block:image] { "images": [ { "image": [ "https://files.readme.io/e3786b2-Screenshot_from_2016-12-06_13-15-29.png", "Screenshot from 2016-12-06 13-15-29.png", 746, 452, "#040404" ] } ] } [/block] However, you may encounter an error like this when installing npm packages globally. [block:image] { "images": [ { "image": [ "https://files.readme.io/7ecea56-Screenshot_from_2016-12-06_12-57-15.png", "Screenshot from 2016-12-06 12-57-15.png", 746, 452, "#060707" ] } ] } [/block] There are a few ways to solve this issue according to [docs.npmjs.com](https://docs.npmjs.com/getting-started/fixing-npm-permissions). We prefer Option 2 as it does not require changing directory ownership, which may be a security risk. First, change the install location of global packages. ``` mkdir ~/.npm-global npm config set prefix '~/.npm-global' ``` Create/edit `.bashrc` to add the new directory to your `PATH`. ``` echo "export PATH=~/.npm-global/bin:\$PATH" >> ~/.bashrc ``` Make sure you are the owner of the `~/.npm-global/` directory, or assert your ownership using the following ``` chown <username>:users ~/.npm-global ``` Restart your terminal and you should be able to install and use global packages. [block:callout] { "type": "info", "body": "The `.bash_profile` is only executed for a login-shell, whereas `.bashrc` is executed for every new shell instance", "title": "You can use .bash_profile instead of .bashrc if you wish." } [/block] [block:api-header] { "type": "basic", "title": "MIPS/OpenWRT" } [/block] If you wish to run NodeJS on an OpenWRT device and node is not already provided for your distribution or node is provided and you require a new version, you should be familiar with [OpenWrt's build system](https://wiki.openwrt.org/about/toolchain). [This article](https://github.com/netbeast/docs/wiki/Cross-Compile-Nodejs-for-OpenWrt) explains how to cross compile NodeJS for OpenWRT. Once you have the NodeJS Binary file, transfer it to your OpenWRT device. You may need to mark it as executable. `chmod node 755` Depending on CPU speeds, we recommend downloading npm packages on a different computer and transfer them to your device. If any of your packages require compilation, you will want to compile them with your toolchain. [block:callout] { "type": "warning", "body": "In our testing, we found that the OpenWRT kernel required FPU emulation be enabled for NodeJS to run. Without FPU Emulation, we tested many different versions of NodeJS (0.10 - 6.0.0), and each would result in a floating point exception or not respond. When compiling your OS make sure that you have this feature enabled.", "title": "FPU emulation" } [/block]