無法在 Ubuntu 16.04 上使用 sudo 開啟 MATLAB

無法在 Ubuntu 16.04 上使用 sudo 開啟 MATLAB

我在 Ubuntu 16.04 上安裝了 MATLAB R2017a。

從控制台,我能夠運行matlab並成功啟動軟體。但是,如果我運行sudo matlab,則會出現以下錯誤:

sudo: matlab: command not found

sudo su我通過先運行然後再運行獲得了相同的響應matlab

我怎麼可能只能在沒有 的情況下運行它sudo?是否有sudo特定的路徑要更新?

答案1

是的,sudo有自己的secure_path。從man sudoers

 secure_path   Path used for every command run from sudo.  If you don't
               trust the people running sudo to have a sane PATH environ‐
               ment variable you may want to use this.  Another use is if
               you want to have the “root path” be separate from the “user
               path”.  Users in the group specified by the exempt_group
               option are not affected by secure_path.  This option is not
               set by default.

(請注意,它Ubuntu 預設值/etc/sudoers)。

如果您決定修改它,請記住使用visudo而不是常規編輯器,以避免在出現語法錯誤時將自己鎖定。

更好的選擇可能是從 Ubuntu 上已有的某個位置創建符號鏈接,sudo secure_path例如

$ ls -ld $(which matlab)
lrwxrwxrwx 1 root root 35 Apr 11  2017 /usr/local/bin/matlab -> /usr/local/MATLAB/R2017a/bin/matlab

最重要的是安排您的裝置權限,這樣就不需要matlab以 root 身分執行。

相關內容