Ubuntu 16.04.03LTS下无需导航目录及root权限启动Matlab咨询
Hey there! Let's get this sorted so you can launch MATLAB from anywhere in your terminal (or even the GUI) without having to navigate to that bin directory or use root privileges. Here's how to do it step by step:
1. Fix MATLAB Directory Permissions (No More Root Required)
First, let's make sure your regular user account has access to run MATLAB. Right now, you need root because the directory permissions are probably restricted. Run these commands (replace your_username with your actual Linux username):
- Take ownership of the MATLAB installation directory:
sudo chown -R your_username:your_username /usr/local/MATLAB/R2015a - Grant your user full read/write/execute access to the directory:
sudo chmod -R u+rwx /usr/local/MATLAB/R2015a
After this, you won't need sudo to start MATLAB anymore.
2. Add MATLAB's Bin Directory to Your User PATH
This lets you run the matlab command from any directory in your terminal, no navigation needed:
- Open your user's shell configuration file (we'll use
.bashrcsince Ubuntu 16.04 uses bash by default):nano ~/.bashrc - Scroll to the very end of the file and add this line:
export PATH=$PATH:/usr/local/MATLAB/R2015a/bin - Save the file (press
Ctrl+O, hit Enter, thenCtrl+Xto exit nano) - Make the changes take effect immediately without logging out:
source ~/.bashrc
Now, just open a terminal (from your home directory or anywhere else) and type matlab — it should launch right up with your regular user permissions.
Alternative: Use a Shell Alias (If You Don't Want to Modify PATH)
If you'd prefer not to adjust your system PATH, you can create an alias instead:
- Open
.bashrcagain:nano ~/.bashrc - Add this line at the end:
alias matlab='/usr/local/MATLAB/R2015a/bin/matlab' - Save, exit, and run
source ~/.bashrcas before. You can now typematlabto launch it from anywhere.
3. Optional: Create a GUI Desktop Shortcut
For even easier access (no terminal required), set up a desktop launcher:
- Create a new desktop entry file:
nano ~/.local/share/applications/matlab.desktop - Paste the following content (the paths should work as-is for your setup):
[Desktop Entry] Name=MATLAB R2015a Exec=/usr/local/MATLAB/R2015a/bin/matlab -desktop Icon=/usr/local/MATLAB/R2015a/bin/glnxa64/cef_resources/matlab_icon.png Type=Application Categories=Development;Science; Comment=MATLAB R2015a - Technical Computing Environment
- Save and exit, then make the file executable:
chmod +x ~/.local/share/applications/matlab.desktop
You'll now find MATLAB in your application menu, and clicking it will launch the GUI directly without any extra steps.
内容的提问来源于stack exchange,提问作者Talha

