Back to top
image_not_found

Getting Ghost Running on Bash on Windows

Well I won’t say that was the easiest process, but I’ve just got an installation of the Ghost blogging platform running on my Bash on Windows system.

I’m never sure if it’s just me or if others experience the same thing, but installations like this just never seem to work as documented for me! All sorts of random errors popped up, I spent 3/4 of my time in Google, some issues I was able to resolve and some I’m not even sure now if I fixed them or if I just “worked around” them so that they will come to bite me in the future!

One thing I read along the way is that npm is not necessarily expected to work on Bash on Windows yet (or at least it wasn’t back in April). However since that was two months ago, and I know a lot has changed in Bash on Windows since then, I didn’t let that put me off my task. I do also only run with the slow ring on the Windows Insider programme, so it’s possible I’m still not on the latest and greatest, BUT I a just upgraded to build 14366 so again thought I’d just give it a go.

I pretty much hadn’t installed anything yet on my Ubuntu system (not even Node, as it turned out), so this is from a bare bones install.

Here’s what I went through to get here, with all the warts and all.

DISCLAIMER: before you start following these instructions, note that I ended up running into a show-stopper issue once I had the Ghost site up and running, which is waiting for a fix by the WSL team (related to network interface sys calls, such as enumeration capabilities). Once this is fixed I’ll just post an update to this disclaimer, but until them you could either carry on and do what I’ve done in the end and have documented below (hard-coding the IP for now), or you may prefer to just hold off and check back here every few weeks to see when I have an update.

This follows roughly the instructions available in Ghost’s Github readme, however as you’ll see I had to change this up a LOT.

Install Node.JS and npm

This part took a few false-starts. First I installed npm - backwards, I know, but I actually assumed that I’d already installed Node.JS when I first got Bash on Windows working weeks ago (my memory is bad, by the way…). So I ran the package manager install:

sudo apt-get install npm

Next I installed Node.JS. This experience included a big lesson for me, as I have installed Node on other servers before and thought that the Ubuntu package manager was just plain out of date with it’s package version of v0.10. Now having been through all of this, at first I grabbed v5.x of Node until I found out that Ghost doesn’t support that latest “stable” version of Node, instead it requires the LTS version (LTS stands for “Long Term Support”). The current LTS version is v4.4.5.

As I said, I originally installed v5.x version of Node, the exact version escapes me now, but once I got to the point of installing Ghost, even running with the configuration option (GHOST_NODE_VERSION_CHECK=false), I was having errors, and since I couldn’t rule out the Node version as being the cause I decided to roll back to installing the latest Node v4.x package.

To do this on Ubuntu, you run the following:

curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs

Install NPM Packages

Next, as per the Ghost readme, I install the Grunt CLI:

npm install -g grunt-cli

Oops, I received an access error (EACCES), so straight away my thought was “yep I’ll just run this as root using sudo”. That does work, BUT later on, after the second time of having this (when installing bower), I decided that it didn’t seem right to have to do this, when no online install documentation seemed to suggest having to run as sudo. So I investigated and found this article about the issue. I ran the command therein to check where the default directory is set for npm, and discovered it is /usr, so on their recommendation I went with their “Option 2” - to move the default directory rather than updating permissions. After following their instructions I tried the installation of grunt-cli globally again, and it appears to have worked. Hooray!

Another undocumented requirement, and I’m not sure if this is because of a bug in the Bash on Window implementation, but the Bower install that is attempted within the grunt built was failing, so I manually installed Bower:

npm install -g bower

Yes another undocumented “thing”, I found that I had to manually install SQLite3 - so hopefully by doing this now it will save you the trouble I went through at the END of the process:

npm install sqlite3 --save

Clone the Ghost Repo

OK this is the easy bit, and worked as expected (woohoo!)… jump into Bash, create a directory (mine is “~/awdghost”) and clone the Gbost github repo into it:

cd ~
git clone git://github.com/tryghost/ghost.git awdghost
cd awdghost 

Install Ghost

Next, as per the readme, I ran the installation of the project, from the root directory (for me this was ~/awdghost)

npm install

This failed the first few times due to the node version issues that I mentioned above, but if you’ve done it as per my above instructions, this should work now without issue. I do get a number of warnings, but I’m going to assume they are not show-stoppers.

Grunt init

Now to try my first attempt at building the thing (not really… I’d already had many false starts by this point,but hopefully some of the above will have helped you avoid those!):

grunt init

I had a number of false-starts with this part, mostly because of timeout errors when downloading packages. I have no idea why that happened the first time and not the second time, but certainly on rerunning it the packages all downloaded happily, so perhaps it was just bad timing during an outage or something. I STILL had issues on the third time, and so finally in a feeling of defeat, I did what it suggested and ran:

grunt init -force

which I presume means that any errors it suffered wouldn’t stop the build from running. Whether or not they SHOULD have, I won’t know - if I have lots of issues in the future with it, I may blame this!

Finally, though, I had a successful build.

It’s Alive!

To start up the site, simply run:

npm start

Once again I’ve cut out a lot of pain here (SQLite3 wasn’t working at first, but the above-mentioned installation fixed that), but basically that was it! I get a happy output to show that all is “well”:

> ghost@0.9.0-beta.2 start /home/bron/awdghost                                  
> node index                                                                    

WARNING: Ghost is attempting to use a direct method to send email.              
It is recommended that you explicitly configure an email service.               
Help and documentation can be found at http://support.ghost.org/mail.           

Migrations: Up-to-date at version 006                                           
Ghost is running in development...                                              
Listening on 127.0.0.1:2368                                                     
Url configured as: http://localhost:2368                                        
Ctrl+C to shut down                                                             

Now it’s running via http://localhost:2368, and I can browser to this using Chrome and I’m away and running.

Uh-oh, Not Quite There (Hack Time)

Back at the console after setting up my Ghost account, I saw that it had issues sending email, or doing anything where it tries to call the Ghost API:

ERROR: EINVAL: invalid argument, uv_interface_addresses

I’ve found this issue which may be related, it seems the network interface functionality of Bash on Windows isn’t quite ready yet. So in the meantime, nothing like a little hack to get around an issue, I’ve changed the place in the code that was trying to take advantage of a system call to get the list of IPs, so it just returns a hardcoded array of the IP. The file is `/core/server/middleware/cors.js’, and I simply commented out the contents of the function getIPs() around line 14, and replace it with:

    function getIPs() {
        return ["127.0.0.1"];
    }

Like I said in my disclaimer above, hacky but it seems to work for now, and will get me going with my Ghost theme development.

(also as an aside, do you see those “ codes in that last code block? It’s painful issues like this that are driving me to move away from WordPress to Ghost, where markdown is a first class citizen… hence this entire exercise!)