os


Insall node and npm with no sudo

I’ve been using node and his good buddy npm for a couple of years now. Up until three days ago, I would happily prefix sudo whenever an npm package gave me an EACCESS error. I’ve always known this is bad practice, but had never encountered an issue. This all changed when I attempted something fairly mundane: Deploy a Hexo blog with Capistrano.

For better or worse, my Capistrano deployment runs npm install as part of its routine. I tried mucking around with sudo and visudo, but to no avail. The blog would simply not deploy because of the restrictive sudo npm install step. At some point it finally occurred to me that npm shouldn’t need sudo anyway, so I’d best fix the problem properly. Instead I did a quick hack on my production server:

The quick hack

Just kidding, this is actually legit, especially given that I’m the only one able to muck around in production. The following is adapted from here. Basically, it allows you to use the -g option without sudo, because all global npm packages get stored under your home directory:

1
2
3
mkdir ~/npm-global
npm config set prefix '~/npm-global'
vim ~/.profile

Append the following to the ~/.profile just opened (or created):

1
export PATH=~/npm-global/bin:$PATH

Now update your system variables:

1
source ~/.profile

Install something globally to make sure it works:

1
npm install -g jshint

A nicer way, arguably

This is more appropriate for a production environment with multiple users. It is adapted from here.

Create a new group:

1
sudo groupadd nodegrp

Add current user to the group (with logname)

1
sudo usermod -a -G nodegrp `logname`

Get access to group:

1
newgrp nodegrp

You can check to see that the user has been added by running:

1
groups

Change group ownership on all the critical components:

1
2
3
sudo chgrp -R nodegrp /usr/lib/node_modules/
sudo chgrp nodegrp /usr/bin/node
sudo chgrp nodegrp /usr/bin/npm

On existing installs

After fixing the issue, there’s a real good chance that root still owns some of the packages installed in the user’s home directory. That’s easy to fix:

1
sudo chown -R $(whoami):$(whoami) ~/.npm

Set up an Ubuntu 14.04 gebo production environment

This document provides step-by-step instructions on how to set up Ubuntu 14.04 for a gebo production and/or development environment. It is comprehensive so that you may copy, paste, and execute the commands and deploy the configurations provided, from beginning to end. Deployed correctly, this environment will host as many gebo-servers and HAIs as the host hardware will allow.

gebo is not dependent on Ubuntu specifically, but requires the same third-party software no matter the operating system you choose.

Let’s get started…

Update the OS

1
2
sudo apt-get update
sudo apt-get upgrade

git

1
sudo apt-get install git

MongoDB

Add the repository

Verify instructions here.

1
2
3
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list
sudo apt-get update

Install

1
sudo apt-get install mongodb-10gen

Start

1
sudo service mongodb start

How to remove

This is for reference. Do not execute these commands unless you want to remove MongoDB.

1
2
3
sudo apt-get purge mongodb mongodb-clients mongodb-server mongodb-dev 
sudo apt-get purge mongodb-10gen
sudo apt-get autoremove

node

1
2
3
4
sudo apt-get install -y python-software-properties python g++ make 
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs

This should also install the Node Package Manager (npm)

grunt-cli

1
sudo npm install -g grunt-cli

bower

1
sudo npm install -g bower

ruby 1.9.3

Newer versions of ruby probably work fine. I hope to remove this dependency in the near future, because it’s really only needed for compass, which I want to get rid of.

1
sudo apt-get install ruby1.9.3

compass

1
sudo gem install compass

forever

1
sudo npm install -g forever

nginx

1
sudo apt-get install nginx

vim

This part is optional. I include it for my own reference, and also because everyone should use vim.

pathogen.vim

1
2
3
4
mkdir -p ~/.vim/autoload ~/.vim/bundle
cd ~/.vim/autoload
wget https://raw.github.com/tpope/vim-pathogen/HEAD/autoload/pathogen.vim
vim ~/.vimrc

Add this to the .vimrc file:

1
2
3
4
5
6
call pathogen#infect()
map <C-n> :NERDTreeToggle<CR>

set softtabstop=4
set expandtab
set cindent

Save and exit.

NERDTree

1
2
cd ~/.vim/bundle 
git clone https://github.com/scrooloose/nerdtree.git

Next

Instantiate a gebo agent…