Deploy to an Ubuntu Server
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:- 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:1.0.0 or similar.
3. Configure the Firewall
Set up basic firewall rules to secure your server:Part 2: Deploy Your Application Code
4. Transfer Your Code to the Server
(replacemyapp with the name of your app)
Option A: Using Git (Recommended)
If your code is in a Git repository:
5. Install Dependencies and Test
Navigate to your app directory and set it up:.env file:
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 theUser and ExecStart paths based on your setup. The Bun path shown is the default installation location.
7. Enable and Start the Service
8. Test the Service
Monitor your service logs in real-time: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:- Access your domain registrar’s DNS management panel
- Create an A record pointing your domain to your server’s IP address:
- Name:
@(for root domain) ormyapp(for subdomain) - Type:
A - Value: Your server’s IP address
- TTL: 300 (5 minutes)
- Name:
11. Create Nginx Virtual Host
Create an Nginx configuration for your domain:myapp.example.org with your actual domain):
12. Activate the Site
Enable your site configuration:13. Test HTTP Access
Test your deployment: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:- Automatically modify your Nginx configuration
- Set up automatic certificate renewal
- Redirect HTTP traffic to HTTPS
16. Test HTTPS
Verify your secure deployment:Part 6: Register with MentraOS
17. Update MentraOS Console
- Navigate to console.mentra.glass
- Sign in and select your app
- Update the Server URL to your domain:
https://myapp.example.org - If using a webview, update the Webview URL to:
https://myapp.example.org/webview - Save your changes
18. Test Your Live App
- Open the MentraOS app on your phone
- Find your app in the app list and tap to start it
- 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:- 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
.envfile contains correct values
Domain Not Accessible
Check DNS propagation:SSL Certificate Issues
Check certificate status:Next Steps
Congratulations! Your MentraOS app is now running on your Ubuntu server with HTTPS. Here’s what you can do next:Explore MentraOS Features
- Events: Handle user interactions and sensor data
- Settings: Add configurable options for users
- AI Tools: Integrate with Mira AI for natural language interactions
- Webview Authentication: Build rich web interfaces
Get Help
- Discord Community: Get help from other developers
- Ubuntu Server Documentation: Learn more about server administration
- Nginx Documentation: Advanced web server configuration
- MentraOS Documentation: Explore the full SDK documentation

