Downloading and installing NW.js
Installing NW.js is pretty simple, but there are many ways to do it. One of the easiest ways is probably to run npm install nw
from your terminal, but for the educational purposes of the book, we're going to manually download and install it in order to properly understand how it works.
You can find all the download links on the project website at http://nwjs.io/ or in the Downloads section on the GitHub project page at https://github.com/nwjs/nw.js/; from here, download the package that fits your operating system.
Tip
For example, as I'm writing this book, Node-Webkit is at version 0.12.0, and my operating system is Mac OS X Yosemite 10.10 running on a 64-bit MacBook Pro; so, I'm going to download the nwjs-v0.12.0-osx-x64.zip
file.
Packages for Mac and Windows are zipped, while those for Linux are in the tar.gz
format. Decompress the files and proceed, depending on your operating system, as follows.
Installing NW.js on Mac OS X
Inside the archive, we're going to find three files:
Credits.html
: This contains credits and licenses of all the dependencies of NW.jsnwjs.app
: This is the actual NW.js executablenwjc
: This is a CLI tool used to compile your source code in order to protect it
Tip
Before v0.12.0, the filename of nwjc
was nwsnapshot
.
Currently, the only file that interests us is nwjs.app
(the extension might not be displayed depending on the OS configuration). All we have to do is copy this file in the /Applications
folder—your main applications folder.
Tip
If you'd rather install NW.js using Homebrew Cask, you can simply enter the following command in your terminal:
$ brew cask install nw
If you are using Homebrew Cask to install NW.js, keep in mind that the Cask repository might not be updated and that the nwjs.app
file will be copied in ~/Applications
, while a symlink will be created in the /Applications
folder.
Installing NW.js on Microsoft Windows
Inside the Microsoft Windows NW.js package, we will find the following files:
credits.html
: This contains the credits and licenses of all NW.js dependenciesd3dcompiler_47.dll
: This is the Direct3D libraryffmpegsumo.dll
: This is a media library to be included in order to use the<video>
and<audio>
tagsicudtl.dat
: This is an important network librarylibEGL.dll
: This is the WebGL and GPU accelerationlibGLESv2.dll
: This is the WebGL and GPU accelerationlocales/
: This is the languages foldernw.exe
: This is the actual NW.js executablenw.pak
: This is an important JS librarypdf.dll
: This library is used by the web engine for printingnwjc.exe
: This is a CLI tool to compile your source code in order to protect it
Some of the files in the folder will be omitted during the final distribution of our application, but for development purposes, we are simply going to copy the whole content of the folder to C:/Tools/nwjs
.
Installing NW.js on Linux
On Linux, the procedure can be more complex depending on the distribution you use. First, copy the downloaded archive into your home folder if you have not already done so, and then open the terminal and type the following command to unpack the archive (change the version accordingly to the one downloaded):
$ gzip -dc nwjs-v0.12.0-linux-x64.tar.gz | tar xf -
Now, rename the newly created folder in nwjs
with the following command:
$ mv ~/nwjs-v0.12.0-linux-x64 ~/nwjs
Inside the nwjs
folder, we will find the following files:
credits.html
: This contains the credits and licenses of all the dependencies of NW.jsicudtl.dat
This is an important network librarylibffmpegsumo.so
: This is a media library to be included in order to use the<video>
and<audio>
tagslocales/
: This is a languages foldernw
: This is the actual NW.js executablenw.pak
: This is an important JS librarynwjc
: This is a CLI tool to compile your source code in order to protect it
Open the folder inside the terminal and try to run NW.js by typing the following:
$ cd nwjs $ ./nw
If you get the following error, you are probably using a version of Ubuntu later than 13.04, Fedora later than 18, or another Linux distribution that uses libudev.so.1
instead of libudev.so.0
: otherwise, you're good to go to the next step:
error while loading shared libraries: libudev.so.0: cannot open shared object file: No such file or directory
Until NW.js is updated to support libudev.so.1
, there are several solutions to solve the problem. For me, the easiest solution is to type the following terminal command inside the directory containing nw
:
$ sed -i 's/udev\.so\.0/udev.so.1/g' nw
This will replace the string related to libudev
, within the application code, with the new version. The process may take a while, so wait for the terminal to return the cursor before attempting to enter the following:
$ ./nw
Eventually, the NW.js window should open properly.