笨熊之家

欢迎来到笨熊之家~

0%

Hexo博客迁移

Debian 3.16.43-2+deb8u2

安装Node.js和Git

首先需要安装Node.jsGit

1
apt-get install git -y

安装Node.js,我用的是nvm

1
2
3
4
wget -qO- https://raw.github.com/creationix/nvm/master/install.sh | sh #wget方式安装nvm
curl https://raw.github.com/creationix/nvm/master/install.sh | sh #curl方式安装nvm

nvm install v6.11.3 #安装对应版本,这里的版本号可以自定义,详见其github主页

随后执行npm install -g hexo-cli是出现错误提示node: Permission denied,可以在这里看到相关的讨论和解决方案。

ljharb commented on 5 Mar
The common thread seems to be global packages that have postinstall scripts that check/fix permissions. I would still suspect that it’s because you’re root - npm runs postinstall scripts as nobody for safety.

这里说npm以nobody身份执行postinstall脚本,所以ljharb认为和root身份关系不是很大。

crazy4groovy commented on 6 Mar
Let’s call this one fixed! :)

I followed the instructions here to create a sudo user (called it worker1): https://www.digitalocean.com/community/tutorials/how-to-create-a-sudo-user-on-ubuntu-quickstart

Then reinstalled nvm in that account.Then:

worker1@ubuntu:~$ npm install testcafe

testcafe-browser-tools@1.2.0 postinstall /home/worker1/node_modules/testcafe-browser-tools
node ./bin/fix-permissions.js

File permissions fixed
/home/worker1
└─┬ testcafe@0.13.0
. . .
I don’t fully understand the ramifications of using a non-root user, but it’s enough to nod my head, cheer, and move along :) Thanks for your help working through this; muchly appreciated kind sir! 👍 May others find this useful as well.

这里crazy4groovy新建一个用户并赋予sudo权限后,安装成功。(原因不明确)

后面也有人提出一种解决在root下安装失败的方案:

Josexv1 commented on 21 Jul
You can run this as root

npm config set user 0
npm config set unsafe-perm true
npm install -g package

source

安装Hexo

npm install -g hexo-cli

拷贝所有文件

1
scp -r /var/www/hexo user@ip:/var/www #这里输入密码后可能会提示错误,原因是user没有在对应目录写的权限,解决方案一是给予对应的写权限,二是先拷贝至用户目录再让user使用sudo mv命令将文件夹移动至最终路径

生成并部署

hexo g d #需要在hexo博客的根目录下执行

这里我还遇到一个问题,就是由于使用nvm管理Node.js,所以相应文件是放在用户家目录下的.nvm目录中,而hexo g d命令又因为需要创建文件所以需要指定目录的所有者权限,于我而言也就是得切换到root用户来执行命令,但切换后Node.js环境又没了,后来发现使用su -p命令即可保留环境。

2018.3.17更新
当时忘记了可以通过chown -hR user /path/to/directory来递归改变指定目录及其子目录的所有者,这样之后就可以正常的使用hexo g d而不需要切换到root用户了。