Mastodon
m7mdharon

Installing and Running LM Studio on Ubuntu as a Headless Server

Nov 27th, 2025
41
0
Never
Not a member of gistpad yet? Sign Up, it unlocks many cool features!
Markdown 11.43 KB | Software | 0 0
  1. # How to Install and Run [LM Studio](https://lmstudio.ai/) on Ubuntu as a Headless Server
  2.  
  3. This guide explains how to install and run LM Studio in a headless Ubuntu environment.
  4.  
  5. ---
  6.  
  7. ## **Prerequisites**
  8. Ensure you have an Ubuntu 24.10 server with sufficient resources for the models you plan to use. For testing, a machine with **2 GB RAM, 2 CPUs, and 60 GB SSD** is sufficient for smaller models.
  9.  
  10. ---
  11.  
  12. ## **Step 1: Install Required Packages**
  13. Run the following command to install all necessary dependencies:
  14. ```bash
  15. sudo apt install -y npm fuse fuse3 libfuse2 libatk1.0-0 libatk-bridge2.0-0 libcairo2 libgdk-pixbuf2.0-0 libgtk-3-0 libx11-6 libnss3 libasound2 libasound2t64 libcups2 xauth xvfb xfce4 xfce4-goodies
  16. ```
  17.  
  18. ---
  19.  
  20. ## **Step 2: Download LM Studio**
  21. Download the LM Studio AppImage from the official site (https://lmstudio.ai/):
  22. ```bash
  23. wget https://installers.lmstudio.ai/linux/x64/0.3.6-8/LM-Studio-0.3.6-8-x64.AppImage
  24. ```
  25.  
  26. Make the file executable:
  27. ```bash
  28. chmod +x LM-Studio-0.3.6-8-x64.AppImage
  29. ```
  30.  
  31. ---
  32.  
  33. ## **Step 3: Run LM Studio with a Virtual Display**
  34. Run LM Studio using `xvfb` to simulate a graphical environment:
  35. ```bash
  36. xvfb-run ./LM-Studio-0.3.6-8-x64.AppImage --no-sandbox
  37. ```
  38. This initializes LM Studio and prepares it for headless operation.
  39.  
  40. ---
  41.  
  42. ## **Step 4: Install the LM Studio CLI**
  43. Install the LM Studio CLI tool (`lms`) using:
  44. ```bash
  45. npx lmstudio install-cli
  46. ```
  47.  
  48. During installation, you’ll see the following prompt:
  49. ```
  50. We are about to run the following commands to install the LM Studio CLI tool (lms):
  51. echo 'export PATH="$PATH:/root/.lmstudio/bin"' >> ~/.profile
  52. echo 'export PATH="$PATH:/root/.lmstudio/bin"' >> ~/.bashrc
  53. ```
  54. Confirm by typing `Yes`. This will add the CLI tool to your PATH.
  55.  
  56. Open a new terminal session or run:
  57. ```bash
  58. source ~/.bashrc
  59. ```
  60.  
  61. Verify the installation:
  62. ```bash
  63. lms --help
  64. ```
  65.  
  66. ---
  67.  
  68. ## **Step 5: Start the LM Studio Server**
  69. Start the server to enable API access:
  70. ```bash
  71. lms server start
  72. ```
  73.  
  74. Check the server status:
  75. ```bash
  76. lms status
  77. ```
  78. You should see output indicating the server is running on port **1234**.
  79.  
  80. ---
  81.  
  82. ## **Step 6: Download and Load a Model**
  83. List available models to download:
  84. ```bash
  85. lms get
  86. ```
  87. Select a lightweight model such as **Qwen2.5 Coder 3B Instruct** and confirm the download. Once downloaded, load the model:
  88. ```bash
  89. lms load qwen2.5-coder-3b-instruct
  90. ```
  91.  
  92. Verify the loaded models:
  93. ```bash
  94. lms ps
  95. ```
  96. ---
  97.  
  98. ## **Step 7: Test the Model via API**
  99. Send a request to the running server to test the model:
  100. ```bash
  101. curl http://localhost:1234/v1/chat/completions \
  102. -H "Content-Type: application/json" \
  103. -d '{
  104. "model": "qwen2.5-coder-3b-instruct",
  105. "messages": [
  106. { "role": "user", "content": "Write a Python function to reverse a string." }
  107. ]
  108. }'
  109. ```
  110.  
  111. ### Example Response:
  112. ```json
  113. {
  114. "id": "chatcmpl-o2nubfsik7bykwbkdysbrd",
  115. "object": "chat.completion",
  116. "created": 1736694420,
  117. "model": "qwen2.5-coder-3b-instruct",
  118. "choices": [
  119. {
  120. "index": 0,
  121. "logprobs": null,
  122. "finish_reason": "stop",
  123. "message": {
  124. "role": "assistant",
  125. "content": "Here's a simple Python function to reverse a given string:\n\n```python\ndef reverse_string(s):\n # Using slicing to reverse the string\n return s[::-1]\n\n# Example usage\nreversed_s = reverse_string(\"hello\")\nprint(reversed_s) # Output: \"olleh\"\n```"
  126. }
  127. }
  128. ],
  129. "usage": {
  130. "prompt_tokens": 38,
  131. "completion_tokens": 116,
  132. "total_tokens": 154
  133. },
  134. "system_fingerprint": "qwen2.5-coder-3b-instruct"
  135. }
  136. ```
  137.  
  138. ---
  139.  
  140. ## **Step 8: Manage Models**
  141. ### List Installed Models:
  142. ```bash
  143. lms ls
  144. ```
  145. ### Unload a Model:
  146. ```bash
  147. lms unload <model-identifier>
  148. ```
  149. ### Stop the Server:
  150. ```bash
  151. lms server stop
  152. ```
  153.  
  154. ---
  155.  
  156. ## **Conclusion**
  157. You have successfully installed and configured LM Studio on a headless Ubuntu server. You can now explore various models and use the API for your projects. If you encounter issues, refer to the LM Studio documentation or seek assistance. 😊
RAW Gist Data Copied