nodejs中安装ghost出错的原因及解决方法

看了标题就知道安装ghost会碰到不少的坑,这里先说一个:

错误

(windows)通过ghost-cli来安装的步骤:

npm install -g ghost-cli #全局安装ghost-cli cd myghostblog #进入工作目录 ghost install local #使用local参数在当前目录初始化一个ghost,使用sqlite数据库

出错信息如下:

√ Downloading and installing Ghost v? √ Finishing install process √ Configuring Ghost √ Setting up instance × Running database migrations A SystemError occurred.

在ghost install local过程中不仅完成了ghost的初始化,还完成了依赖库的安装(也就是npm install)

从错误提示中看到Running database migrations出错了,其原因是:在下载依赖包sqlite3时出错,导致问题出现。

实际上在下载依赖包时出错,仅仅给出一个警告,警告都会跳过去,直到migrator这一步(数据迁移,也就是初始化数据库)出现了错误,导致安装失败。

而为什么下载sqlite3时出错了呢?

原因

就是因为sqlite3的包(sqlite3 for node)在.s3.amazonaws.com上,这个被墙了。*(满眼的泪呀!)

知道了原因,要解决就很容易了。

解决

解决方案是: cnpm install sqlite3 #使用taobao镜像安装

具体的过程如下:

npm install -g ghost-cli cd myghostblog ghost install local #会出错 cd current cnpm install #补装依赖库,并使用taobao镜像安装 knex-migrator init #初始化sqlite数据库,会使用MigratorConfig.js grunt dev #运行 Dev 环境

打开浏览器:2368/

加强

上面是在current目录下使用grunt运行起来的,如果要回到ghost-cli通过ghost来运行的话,还需要做一件事,将myghostblog\current\content\data\ghost-dev.db文件拷贝到myghostblog\content\data\ghost-dev.db,并修改文件名为ghost-local.db。(注意看目录差别,中间有一个current目录的差别)

这样就可以回到myghostblog目录使用ghost start来启动了。

cd myghostblog ghost start

打开浏览器:2368/

最后再说一下环境

windows 10 Node Version: v6.10.3 Ghost-CLI Version: 1.1.3 Ghost Version: 1.14.0 2017-10-23

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wywfxx.html