Building on Midnight with Windows: A Real Developer’s WSL2 Setup Guide
Working in an unstable environment completely kills programming creativity. A professional developer first focuses on building and securing their work’s foundation. Today, we will build an environment that doesn’t collapse under continuous work pressure. The core Midnight tools are built exclusively for Linux environments. If you use Windows, you cannot run them directly. The only professional solution is to rely on WSL2 development for developers.
The deadline for an e-commerce platform was Friday morning. On Thursday night, the development server completely collapsed under data pressure. The environment failed due to library conflicts between Windows and the production server. A lot of time was lost in exhausting manual repair attempts. I felt intense frustration because the client in Casablanca depended on us. The error was trivial but posed a real commercial threat to the project.
That’s when I decided to immediately switch to a Linux environment as my primary choice. This system provided me with complete stability and server compatibility. This decision ended the nightmare of programming incompatibility that consumed my team’s time. The environment setup time reduced from four hours to thirty minutes. We delivered the project twelve hours ahead of schedule. This struggle prompted me to found TwiceBox later to offer better solutions.
I believe Moroccan companies deserve a robust technical infrastructure. Excellent infrastructure enables companies to compete globally with high quality. We must not accept any compromise on the quality of our software tools.
Setting Up a WSL2 Development Environment for Developers on Windows

The Windows Subsystem for Linux is no longer just a secondary tool for programmers. It is the foundational layer for running modern blockchain tools efficiently. Without it, you remain stuck in a cycle of extremely complex compatibility issues.
Enabling WSL2 Features via PowerShell
We always start by opening a PowerShell terminal with administrative privileges. This step is crucial for securely modifying deep system settings. Without these privileges, essential installation commands will fail immediately.
Executing the wsl --install command handles the download of the core system kernel. The system will download the necessary files directly from Microsoft servers. After restarting your computer, you must verify the system version.
Use the wsl --set-default-version 2 command to set Version 2 as the default. Version 1 does not support the Docker containers required for your upcoming projects. Ensure the operation was successful by typing wsl --list --verbose in the terminal.
If you encounter an error message during activation, check your BIOS settings. You must enable virtualization technology on your computer’s motherboard. Without enabling virtualization, the Linux subsystem will never function.
In a previous project, I experienced severe slowness in the compiler. The reason was the subsystem remaining on the old Version 1. I updated the version, and the file processing speed tripled.
Installing Ubuntu and Setting Up a User Account
Open the Microsoft Store and search for the Ubuntu 24.04 LTS distribution. This specific version offers ideal stability for modern blockchain tools. Avoid older versions as they lack required software security updates.
After downloading, open the application to begin the initial system setup process. The system will prompt you to enter a new username and password. Choose a simple name that is easy to type later in file paths.
When typing your password, no characters will appear on screen. This is normal Linux security behavior to protect data. Type the password and press Enter confidently to complete the process.
Remember that a Linux user has limited privileges by default. You will need to use root commands for certain sensitive system modifications. This prevents accidental changes that could corrupt system files.
You can refer to the comprehensive guide to setting up the environment for more precise details. This additional resource helps you understand some complex variables. After successful installation, we must proceed to configure technical resources.
Optimizing Memory and Processor Performance for the Work Environment
The default settings for the subsystem are insufficient for decentralized web applications. Ignoring this step will lead to the proof server crashing suddenly and silently. Resource allocation is always the secret to stable professional development environments.
Allocating RAM and Swap Resources
The system allocates only one gigabyte of RAM by default. The Midnight proof server requires at least four gigabytes to operate. Relying on advanced settings helps in successfully analyzing real-time data.
Open a Windows terminal and type the command notepad "$env:USERPROFILE\.wslconfig". This command opens the hidden subsystem configuration file. Add the value memory=8GB to provide sufficient space for complex cryptographic processing.
Also add swap=3GB to prevent system freezes during peak load. Adding processors is done by typing processors=4 to accelerate code compilation. Save the file carefully before closing the text editor window.
The hidden configuration file is read by the system on every boot. Properties must be written under the [wsl2] section exclusively to function correctly. Lines written outside this section are completely ignored by the Microsoft interpreter.
I worked on a very complex script to generate advanced smart contracts. The process stopped completely without any clear error message for the developer. I increased the memory to eight gigabytes, and generation completed in seconds.
Enabling Localhost Forwarding
Communication between your Windows browser and Linux services requires precise forwarding. You must add localhostForwarding=true within the same configuration file mentioned earlier. This line ensures you can access the development server via your browser.
Without this forwarding, you cannot preview the user interface. Services will run in the background but remain isolated from your browser. Save and close the file, then execute the wsl --shutdown command to close.
Port forwarding solves the issue of isolated networks between Windows and Linux. The system creates a virtual bridge that passes data instantaneously. This bridge facilitates API calls during development.
Wait a few seconds, then reopen your Ubuntu distribution. This action ensures the new settings are applied directly to the kernel. Resource optimization paves the way for smoothly installing heavy software engines.
Installing Essential Development Tools: Node.js and Docker

Software engines are the backbone of any successful decentralized project. Choosing the correct versions avoids long hours of debugging. Randomly installing tools completely destroys the stability of your work environment.
Managing Node.js Versions with NVM
The Midnight platform requires Node.js version 22. Do not install the Windows-specific version to avoid path conflicts. Conflicts between two systems lead to immediate compilation command failures.
Use the NVM tool to manage versions within the Linux system itself. Download the installer via the system’s core cURL library. Type the direct download command from the official repository to ensure security.
Execute the nvm install 22 command, followed by nvm use 22. These commands make the new version the default in your environment. Verify the operation was successful by typing node --version in the terminal.
I always recommend adding a version file to specify the active engine version. This file ensures a unified work environment among all developers. This way, we avoid compatibility errors when sharing code with the team.
While building a wallet application, I mistakenly used an old version. The compilation process failed due to unsupported language features. Updating using direct management resolved the issue in just two minutes.
Running Docker Engine within Linux
The network’s proof server runs as an isolated container within the Docker engine. Avoid using the Windows desktop version entirely here. Installing the native Linux engine provides faster performance and greater stability.
First, add the official software repository to Ubuntu’s package list. Execute the sudo apt install docker-ce command to install the essential packages. These packages include the engine and the command-line tools necessary for operation.
Add the current user to the container group to avoid using root privileges. Use the command sudo usermod -aG docker $USER to perform this. Then execute newgrp docker to update privileges without restarting.
If containers fail to start, check the container engine’s error logs. Type journalctl -u docker.service to read detailed system operational reports. The problem is often related to insufficient hard drive space.
Start the service by typing sudo service docker start in the terminal. Immediately test the engine’s functionality by running the program’s default welcome container. After configuring the engines, it’s time to fetch specialized network tools.
Setting Up the Compact Toolchain
The Compact language is the official tool for writing network smart contracts. Installing its compiler requires precision in path settings. Incorrect paths prevent the system from recognizing compiler commands.
Installing the Compiler and Setting the PATH
The development team provides a unified installation script to fetch binary files. You can download and run it directly via the system’s integrated command line. Use the secure communication protocol with the tool to fetch the latest version.
After the download completes, you must define the program’s path in the system. Open your personal configuration file .bashrc using the local text editor. Add the hidden folder’s path to the system’s primary environment variable.
This step makes the compiler available for use from any directory. Type export PATH="$HOME/.local/bin:$PATH" at the end of your personal configuration file. Ensure you save the changes before exiting the text editor.
Verify that the binary files have execution permissions after downloading. Use the chmod +x command on the compiler file to enable its operational capability. The Linux system prevents the execution of downloaded files as a strict security measure.
I attempted to compile a smart contract in a new and very urgent project. An error appeared stating the compiler command was not found. I added the path to the terminal, and the compilation process succeeded within ten seconds.
Verifying Installation Integrity
Do not assume the installation is complete without actually testing the tool. Update your current terminal settings using the direct source command. Type source ~/.bashrc to apply changes without closing the terminal window.
Type the command compact --version to verify the system is reading the files. The latest version number should appear clearly. The appearance of the number means the compiler is ready to process your code.
If the problem persists, close all open terminal windows. Reopen them for the system to load the updated variables. Sometimes the system gets stuck reading the old version of the settings.
If an error message appears, check the correctness of the installation path. Ensure the version is compatible with your personal computer’s processor architecture. The environment is now fully ready to build your first integrated decentralized project.
Building Your First Project with create-mn-app

Scaffolding tools save hours of repetitive coding. The official tool builds the project structure and prepares compilation settings automatically. This gives you more time to focus on complex business logic.
Generating Project Structure and Handling Wallets
Use the scaffolding command to create your new project folder and prepare its files. Type npx create-mn-app my-app in the command line to start the process. The system will ask you to choose a starting template suitable for your current work.
The simple counter template provides a practical example for writing smart contracts. After generating the files, navigate to the folder and execute the comprehensive setup command. Type npm run setup to install packages and configure the development environment.
The script will prompt you to create a new digital wallet and store its data. Save the seed phrase in a secure location and never share it. These words are the only key to accessing your digital assets.
The project folder contains a file for managing the contract’s software dependencies. Review this file to understand the structure of the packages it relies on. You should not manually modify versions to avoid breaking package compatibility.
In a test project, I accidentally uploaded wallet files to a public repository. Thousands of test coins were immediately stolen from the wallet without recourse. I added the file to the ignore list, protecting our data one hundred percent.
Activating the Proof Server
The proof server operates in the background to process zero-knowledge proofs. The setup script automatically starts the container via the container manager. This complex process occurs without any manual intervention.
Ensure no other services are using the same ports. Port 6300 is exclusively dedicated to the application’s connection with the local proof server. Any port conflict will prevent the application from generating proofs.
The script relies on aggregated configuration technology to run multiple containers. It links the proof server to a temporary database to speed up queries. This architectural design perfectly mimics the performance of actual production networks.
You can review container logs to monitor the complex proof generation process. Stability here entirely depends on the memory settings we configured. The project is ready, and the next step is to move it to the actual test network.
Deploying Smart Contracts to the Preprod Test Network
Deployment is the true test of all previous tools working together. The test network provides a secure environment to accurately simulate real production. Here, you confirm the correctness of the contract logic and the user interface’s integrity.
Funding Your Wallet via Faucet
Every transaction on the blockchain requires a small fee for processing. These fees are paid using digital assets accumulated in the wallet. Gas fees are automatically generated when you possess the native currency.
Copy your new wallet address and navigate to the test token faucet website. Ensure you select the correct test network before pasting the address. Paste the address and request to fund your account to begin the actual deployment process.
Wait a few minutes for sufficient fees to accumulate in your account. Rushing will result in an error message stating insufficient available balance. The network needs time to process your request and credit your balance to the blocks.
The network requires time to calculate your balance and convert it into usable gas fees. This mechanism prevents network flooding attacks with repeated fake transactions. Be patient and monitor your balance via the explorer before attempting deployment.
I tried to deploy a complex contract immediately after receiving the test tokens. The transaction failed due to insufficient gas accumulated in the wallet. I waited five minutes, then retried, and the operation succeeded smoothly.
Executing the Deployment Command and Handling Errors
Execute the npm run deploy command to begin broadcasting the contract to the network. The script will compile the code and generate proofs before the actual broadcast. This process takes a few minutes, depending on the smart contract’s complexity.
Monitor the terminal to follow the transaction’s progress and confirmation in the network blocks. Upon success, a link will appear to preview the transaction in the explorer. Open the link to confirm the contract has been successfully added to the network.
If you encounter a compatibility-related error, consult the official network documentation. Smart contract versions are periodically updated to improve security. Keeping up with updates ensures your applications continue to run without interruption.
If an error related to version mismatch appears, update the project’s packages. The scaffolding tool usually detects these issues and suggests fixes. Understanding these basic steps leads us to learn advanced working techniques.
Hidden Secrets to Overcoming Proof Server Crashes
At the beginning of my journey with the network, I faced extremely fatal slowness. The compilation process took a full ten minutes for every modification. This repeated delay destroyed the workflow and caused me frustration.
I discovered the error was storing project files in Windows paths. Accessing files via the /mnt/c/ path kills Linux system performance. Read and write operations between the two systems consume processor resources aggressively.
I moved the entire project folder to the root path ~/. The result was truly astonishing by all recognized technical standards. The system regained its normal speed in processing complex code files.
Compilation time reduced from ten minutes to thirty seconds. This simple adjustment incredibly doubled my daily productivity. Always keep your project files within a completely isolated Linux environment.
Your Next Step in the Midnight World
You have now built a solid and reliable development environment on your system. Precise resource settings and correct software installation are the keys to your success. You can now focus on writing your application logic without distraction.
Open your device’s terminal now and execute the command to create the default project. Monitor your first transaction on the test network explorer today. Contact us to build your next application.
