Debian 3.16.43-2+deb8u2
安装Node.js和Git
1 | apt-get install git -y |
安装Node.js,我用的是nvm。
1 | wget -qO- https://raw.github.com/creationix/nvm/master/install.sh | sh #wget方式安装nvm |
随后执行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.jsFile 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 rootnpm config set user 0
npm config set unsafe-perm true
npm install -g package
安装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用户了。