Installing MEAN stack on a Linux machine is not an easy ride, compared to a windows machine. You are to play a lot with the terminal before and after the installation because that’s the way MEAN is built. There are many ways to setup MEAN on Linux, and I’m going to list the steps that I’ve taken to install it on Ubuntu 15.10 (Wily Warewolf).
Installing Node.js and npm Via nvm
nvm is a simple bash script used to install and maintain different versions of node on your local machine. Install it by using the following command in terminal:
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.29.0/install.sh | bash
The script clones the nvm repository to ~/.nvm and adds the source line to your profile ( ~/.bash_profile, ~/.zshrc or ~/.profile).
To download, compile and install the latest version of node, do this:
nvm install 4.2.2
Now, you can use this version of node in any new shell by doing this:
nvm use 4.2.2
You can also install old versions of node and use any of them by using the above command followed by that version.
You’ll need npm which is a node package manager to setup and use MEAN. npm comes built-in with node. You don’t need to do anything to install it. If you want to upgrade to the latest version, simply do this:
npm install -g npm
This will install the latest version globally on your computer.
That is all you need to setup node. Next are the steps to setup MongoDB.
First, import the mongodb public GPG key using:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
After that, get the package from the Debian wheezy repository using:
echo "deb http://repo.mongodb.org/apt/debian wheezy/mongodb-org/3.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
Then, update the local packages database:
sudo apt-get update
And finally, install the latest stable version of MongoDB using:
sudo apt-get install -y mongodb-org
Now, if you try to start MongoDB normally by using
sudo service mongodb start, it will fail to start. Following are the steps to workaround this problem and start mongodb normally:
/data/db directory and open the MongoDB configuration file in a text editor of your choice.
sudo mkdir -p /data/db
sudo gedit /etc/mongod.conf
Replace dbpath=/var/lib/mongodb with dbpath=/data/db and then save the file.
sudo chown -R mongodb:mongodb /data/db
Now, you are good to go. Start mongodb normally by issuing the following commad:
sudo service mongod start
To check the service status, use the command:
sudo systemctl status mongod
That’s all you need to setup MongoDB. Next are the steps to setup MEAN.
First, install Bower which is a package manager to manage front end packages like angularjs, bootstrap, jquery etc. Do this to install bower globally:
npm install -g bower
Also, install Grunt which is a task runner to automate your development process by doing this.
npm install -g grunt-cli
This will install the grunt command line tool globally on your system.
To download MEAN, clone the git repository into your project folder directly via git uisng:
git clone https://github.com/meanjs/mean.git meanjs
Now open the mean folder, open the terminal in the present folder and run the follwing command:
This will install all the dependencies required by the project. All the dependencies exist in the package.json file.
Finally run grunt using:
This will automatically open a new page in your default browser showing the MEAN.JS welcome page.
Note – After running grunt, there may be an error message that says “couldn’t start MongoDB on default port 27017." In that case, you can start MongoDB on the default post by issuing the command mongod — port 27017 as superuser.
Give yourself a pat on the back as you’ve successfully setup MEAN Stack on your Ubuntu 15.10. Now start building your awesome MEAN application.