The MEAN stack is a JavaScript-based framework for developing dynamic JAVA-based websites and applications. The stack consists of MongoDB, Express, Angular, and Node. Using the MEAN stack, developers can standardize on proven technologies and spend more time working on applications, rather than gluing lots of separate components together. If you want to build fast, dynamic, and robust web applications, the MEAN stack is one way to go. Below are steps that show you how to install it on Ubuntu Linux.
How to install and use the MEAN stack on Ubuntu Linux
As described above, the MEAN stack is a JavaScript-based framework for developing dynamic JAVA-based websites and applications. The stack consists of MongoDB, Express, Angular, and Node. Below is how to install it on Ubuntu Linux.
Install MongoDB
MongoDB is represented by M in MEAN. It is a document database. By default, it’s not included in Ubuntu repositories, so you will have to add its repository if you want to install it. Before, that, run the commands below to add the necessary dependencies to add APT repositories to Ubuntu. To install MongoDB, add its repository’s GPG key to sign its packages. Run the commands below to do that. Next, run the commands below to create a repository file for MongoDB on Ubuntu Linux. Make sure to replace the highlighted Ubuntu core name in the command with your system’s core number. Ubuntu 20.04 code name is focal. After adding the repository GPG key and file, run the commands below to update the Ubuntu packages index and install MongoDB. If you run into problems installing MongoDB, run the commands below to install these dependencies. Additional resources on installing and managing MongoDB database can be found at the link below. How to install and manage MongoDB database on Ubuntu Linux
Install Node.js
Express(.js), Angular(.js), and Node(.js) are all web frameworks based on JavaScript. Express.js is a fast, minimalist web framework for Node.js Angular.js is a fully extensible toolset and libraries for building web and app frameworks based on Node.js and JavaScript. Node.js is the premier JavaScript web server. Let’s first install Node.js and then get the other packages installed after. Node.js packages are included in Ubuntu default repositories. However, the version included in Ubuntu might not necessarily be the latest. To get the latest, you will have to add the Node.js repository. Run the commands below to download the Node.js version 18 repository script. Once downloaded and executed, run the commands below to install Node.js version 18. Additional packages recommended to install with the MEAN stack can also be installed using the commands below Additional resources on installing and using Node.js on Ubuntu Linux can be found at the link below. How to install and use Node.js on Ubuntu Linux
Install MEAN stack
At this point, we are ready to download the MEAN stack from GitHub. The git package includes all the required dependencies that are used with MEAN development. Run the commands below to clone the package from GitHub. Once downloaded, run the command below to install all dependencies.
Create a Node.js web app
Now we have all the MEAN packages and dependencies installed. Let’s build our first app. First, run the commands below to edit the server.js file in the MEAN directory. When the file opens, copy and paste the lines below into the file and save. After saving the file, run the commands below to start the server. When the server starts, it should output something similar to the lines below. To enable the web app to automatically startup when the system boots, run the commands below. The command above will output similar lines as the ones below. You will be prompted to run the highlighted commands above to enable the app to automatically startup every time you start the system. The application is started and is using port 3000. To access it, open your web browser and browse to the server’s hostname or IP address followed by port number 3000.
Run MEAN app with reverse proxy
To efficiently run your MEAN stack app, it is recommended that you run it behind a reverse proxy. Below are two posts that showed you how to set up a reverse proxy with Nginx and Apache HTTP server.
How to set up a reverse proxy with Nginx How to set up a reverse proxy with Apache
That should do it! Conclusion: This post showed you how to install and use the MEAN stack on Ubuntu Linux. If you find any error above or have something to add, please use the comment form below.