如何在XAMPP-VM终端使用系统已安装的命令行工具?
Got it, let's break down why this is happening first—then fix it.
XAMPP-VM runs its own isolated Linux virtual machine, and the terminal you open through XAMPP is tied to that VM, not your host system's shell. That’s why tools like sass or npm you installed on your host aren’t available here: they live in a completely separate environment, and the VM doesn’t know where to find them.
Here’s how to make your host’s tools accessible without reinstalling anything:
Step 1: Locate your host’s tool paths
First, open your host system’s terminal (not XAMPP’s) and run these commands to find where sass and npm are installed:
which sass which npm
You’ll get output like /usr/local/bin/sass or /Users/your-username/.nvm/versions/node/v18.16.0/bin/npm—save these paths.
Step 2: Find the host directory mount point in XAMPP-VM
Open your XAMPP-VM terminal and check where your host’s file system is mounted:
ls /host_mnt
You should see your host’s root directories (like usr, Users) here. XAMPP-VM typically mounts your entire host system to /host_mnt, so a host path like /usr/local/bin translates to /host_mnt/usr/local/bin in the VM.
Step 3: Temporarily add the host’s path to the VM’s PATH
Test if this works by running this command in the XAMPP-VM terminal (replace the path with the one you found in Step 1):
export PATH=$PATH:/host_mnt/usr/local/bin
Now try running sass --version or npm --version—they should work! Note: This change is temporary; it’ll reset when you close the terminal.
Step 4: Make the change permanent
To keep the host’s tools available every time you open the XAMPP-VM terminal:
- Open the bash configuration file in the VM:
nano ~/.bashrc - Add this line at the bottom (replace the path with your host’s tool directory):
export PATH=$PATH:/host_mnt/usr/local/bin - Save and exit: Press
Ctrl+O, hit Enter, thenCtrl+X. - Apply the changes immediately:
source ~/.bashrc
Notes for custom tool locations
If your tools are installed in a user-specific directory (like ~/.nvm for Node.js), adjust the path to match the mounted location. For example, a host path /Users/jane/.nvm/versions/node/v18.16.0/bin becomes /host_mnt/Users/jane/.nvm/versions/node/v18.16.0/bin in the VM.
If you run into permission errors, double-check that your host directory has read access for all users (most default setups already do this).
Hope this gets you up and running with your existing tools!
内容的提问来源于stack exchange,提问作者nth-chile

