Skip to main content
Advanced guide. For your first app, we recommend to deploy using Railway.
This guide will walk you through deploying your MentraOS app to an Ubuntu server. This approach gives you full control over your hosting environment and is ideal for production deployments that require custom configurations or integration with existing infrastructure.

Why Use an Ubuntu Server?

Benefits of Ubuntu server hosting:
  • Full Control: Complete control over server configuration, security, and performance
  • Cost Effective: Often more economical for long-running production applications
  • Custom Infrastructure: Integrate with existing databases, monitoring, and security systems
  • No Platform Lock-in: Your deployment isn’t tied to a specific hosting platform
  • Advanced Configuration: Custom SSL certificates, load balancing, and networking

Prerequisites

Make sure you have:
  • Ubuntu Server: 22.04 LTS or later (physical server, VPS, or cloud instance)
  • Domain Name: A domain pointing to your server’s IP address
  • SSH Access: Root or sudo access to your Ubuntu server
  • MentraOS Account: For the developer console at console.mentra.glass
  • Basic Linux Knowledge: For server administration and troubleshooting

Part 1: Prepare Your Server

1. Update the Operating System and Install Essentials

Connect to your Ubuntu server via SSH and update the system:
What this does:
  • Updates all system packages to the latest versions
  • Installs development tools needed for building applications
  • Installs UFW (Uncomplicated Firewall) for security
  • Installs Git for code management

2. Install Bun Runtime

Install Bun, the fast JavaScript runtime that MentraOS apps use:
You should see a version number like 1.0.0 or similar.

3. Configure the Firewall

Set up basic firewall rules to secure your server:
Note: Always ensure SSH access is allowed before enabling UFW to avoid being locked out of your server.

Part 2: Deploy Your Application Code

4. Transfer Your Code to the Server

(replace myapp with the name of your app) Option A: Using Git (Recommended) If your code is in a Git repository:
Option B: Using SCP If you’re uploading from your local machine:
Example Directory Structure:

5. Install Dependencies and Test

Navigate to your app directory and set it up:
Configure your .env file:
Test your application:
In a separate terminal, test the health endpoint:
You should see a response indicating your app is running. Press Ctrl+C to stop the test server.

Part 3: Create a System Service

6. Set Up Systemd Service

Create a systemd service to run your app automatically and restart it if it crashes: Note: Adjust the User and ExecStart paths based on your setup. The Bun path shown is the default installation location.
Add the following configuration:

7. Enable and Start the Service

8. Test the Service

Monitor your service logs in real-time:
In a separate terminal, test your app:
Your app should respond successfully. The service will automatically restart if it crashes.

Part 4: Configure Web Server and Domain

9. Install and Configure Nginx

Install Nginx as a reverse proxy to handle web traffic:

10. Point Your Domain to the Server

Configure your domain’s DNS settings:
  1. Access your domain registrar’s DNS management panel
  2. Create an A record pointing your domain to your server’s IP address:
    • Name: @ (for root domain) or myapp (for subdomain)
    • Type: A
    • Value: Your server’s IP address
    • TTL: 300 (5 minutes)
Example DNS configuration:

11. Create Nginx Virtual Host

Create an Nginx configuration for your domain:
Add the following configuration (replace myapp.example.org with your actual domain):
For multiple domains (with www prefix):

12. Activate the Site

Enable your site configuration:

13. Test HTTP Access

Test your deployment:
You should see successful responses and request logs.

Part 5: Add HTTPS with Let’s Encrypt

14. Install Certbot

Install Certbot for free SSL certificates:

15. Obtain SSL Certificates

Get SSL certificates for your domain:
Certbot will:
  • Automatically modify your Nginx configuration
  • Set up automatic certificate renewal
  • Redirect HTTP traffic to HTTPS

16. Test HTTPS

Verify your secure deployment:
Your app should now be accessible via HTTPS with a valid SSL certificate.

Part 6: Register with MentraOS

17. Update MentraOS Console

  1. Navigate to console.mentra.glass
  2. Sign in and select your app
  3. Update the Server URL to your domain: https://myapp.example.org
  4. If using a webview, update the Webview URL to: https://myapp.example.org/webview
  5. Save your changes

18. Test Your Live App

  1. Open the MentraOS app on your phone
  2. Find your app in the app list and tap to start it
  3. Expected behavior:
    • Your app should connect successfully
    • Any functionality should work as expected

Part 7: Monitoring and Maintenance

19. Set Up Log Monitoring

Monitor your application logs:

Troubleshooting

App Not Starting

Check service status:
Common issues:
  • Permission errors: Check file ownership with ls -la /opt/myapp
  • Port conflicts: Ensure port 3000 isn’t used by another service
  • Environment variables: Verify your .env file contains correct values

Domain Not Accessible

Check DNS propagation:
Check Nginx configuration:

SSL Certificate Issues

Check certificate status:
Renew certificates manually:

Success!!

Congratulations! Your MentraOS app is now running on your Ubuntu server with HTTPS. Your MentraOS app is now production-ready and running on your own infrastructure!

Next Steps