{"metadata":{"image":[],"title":"","description":""},"api":{"url":"","auth":"required","results":{"codes":[]},"settings":"","params":[]},"next":{"description":"","pages":[]},"title":"Node.js Setup: Linux/Embedded Systems","type":"basic","slug":"install-nodejs-on-linux","excerpt":"","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]","updates":[],"order":4,"isReference":false,"hidden":false,"sync_unique":"","link_url":"","link_external":false,"_id":"59d01d530cd4dd0010294e3f","project":"568bdc1483d2061900d86cdc","version":{"version":"0","version_clean":"0.0.0","codename":"","is_stable":true,"is_beta":true,"is_hidden":false,"is_deprecated":false,"categories":["59a7236e3fe4d90025117c10","59a72eb6cb0db3001b84cfe2","59a734eb757d030019b85af8","59c0243b1b2d07001a9d2b76","59c035e42126e10028effb12","59c06c40df5b3c0010584a13","59c1a5852cabe5002641a3e7","59c2fb00b2b45c0010b7a3d7","59c32ceb9aea850010ac4130","59c32e6e190c90003cb0d12f","59c33affb2b45c0010b7aa23","59c7dfa457bd8200105444dc","59c7e975c50cf30010d712a0","59cffdef0cd4dd0010294d54","59d0622ca91a810032c8f60c","59d06733c1aec60026253065","59d174d44ac471001a07b123","59d5a5e323e6e800103defb2","59ecf1d8ed507c001c52b255","59f76fef8581dc0010593e6f","5a0c003680a35b0012c35db0","5a8358722e78660075e45f42","5a846645b5ec3a001203517e","5b258091bc7a6700033b9cb5","5b26e48e024807000315a740","5b44edff3306680003663f5c","5b468abd3d4a9e0003789111","5b468d8f3dcb6a0003c6e374","5b47b0b93d4a9e000378a33a","5b538d114ea24f00033c726f","5b6a0efe402b32000336c33f","5bba5e5d7ba7710003bd902a","5bc2703349ac3a0013eec3e5","5c351061191e2b002b4988a8","5c8b01b199b56e00440aa018"],"_id":"59a72290d61777001b6c42c3","project":"568bdc1483d2061900d86cdc","createdAt":"2017-08-30T20:39:44.453Z","releaseDate":"2017-08-30T20:39:44.453Z","__v":35},"category":{"sync":{"isSync":false,"url":""},"pages":[],"title":"Droplit Command Line","slug":"droplit-command-line","order":3,"from_sync":false,"reference":false,"_id":"5b26e48e024807000315a740","project":"568bdc1483d2061900d86cdc","version":"59a72290d61777001b6c42c3","createdAt":"2018-06-17T22:45:34.506Z","__v":0},"user":"58cc41f21751ce2f003be3b7","createdAt":"2017-09-30T22:40:19.516Z","githubsync":"","__v":0,"parentDoc":null}