Sublime Forum

Why doesn't Sublime3 use global PATH variable? And how can I force it to use it?


But isn’t the PATH in my .bashrc already doing that?

What is the difference between .bashrc and .bash_profile ?

I know I’m using the .bash_profile on my Macbook.

But this problem happens on my Linux machine and I dont even have a .bash_profile here, because I use .bashrc




OK so I created a .bash_profile and added this to it:

if [ -f ~/.bashrc ]; then
source ~/.bashrc

However it still isn’t working. Sublime still cannot use rustc.

Please please please please: How can I force Sublime to just use my PATH. That’s all I want to know.

I want to click on the Sublime icon in my dock and then Sublime starts, has the correct Path variables and I can just start programming.

That’s all I want.

So again: PLEASE Somebody tell me how I can achieve that!



@kli6891: I dont think thats true. The error message also shows this:

[path: /usr/local/bin:/usr/local/sbin:/usr/bin:/var/lib/flatpak/exports/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl]

So Sublime has some PATH. Just not the correct one. Shouldn’t I be able to add additional PATHs to this?



If you don’t want to solve the underlying problem, you can always fix it at the closest level to where you are invoking rustc. See and the env key.



@wbond: So there is really absolutely no way to specify the PATH that Sublime should use? (If I dont want to start it from the command-line, but per *.desktop file) ?

I just want to be sure I understood this correctly. No settings-option I can use or anything similar?

The only way to get Sublime to use my PATH is to start Sublime from the terminal.

Did I understand tis correctly?



I think I’ve told you two different ways to do it. Modify your .desktop file, or tweak the .sublime-build file. Either should work.

The third way is to actually fix your login shell environment, as @kli6891 suggested. Did you log out of your machine and log back in after modifying .bash_profile?



I have added this to my .bash_profile:

if [ -f ~/.bashrc ]; then
source ~/.bashrc
export PATH="$HOME/.cargo/bin:$PATH"

and rebooted my system. Sublime still doesn’t take the correct PATH variables.

I don’t want to have a custom build system because then auto-detection isnt going to be working anymore right? And I switch a lot between languages. Unfortunately there’s also no keyboard shortcut for changing build systems. I just want to press Ctrl+B and have the autodetected build system being run.

I guess I’ll have to give up :frowning:

Thanks for your help everybody though!!



If I were to customize a .sublime-build, I would use an override, as discussed at the end of That way Sublime will only know about your version and nothing in your workflow needs to change.



So just to make sure I understand this.

Sublime comes with a standard Rust sublime build system file? Thats the one I’m using right now correct?
Where is this file located?

Can you please just tell me what to do? What file exactly do I open and what do I change within that file. I am completely and utterly lost.



UPDATE: I just built a custom Rust build system and added the PATH manually.

Is there a way to specify that this new custom build system is to be used when Sublime auto-detects that this is a Rust file?

So that I can have the Build System setting set to “Automatic” and whenever I open a rust file, Sublime automatically uses MY CUSTOM build system instead of the one coming with Sublime?

That would pretty much solve my problem completely!



Sublime ships with a Rust.sublime-build file in the Rust package. Packages that ship with Sublime are stored as sublime-package files (really just a zip file) and are stored alongside the binary to stop you from having the urge to modify them directly, since when Sublime updates they get replaced wholesale.

You can view the contents of the file by using the View Package File command from the command palette and selecting Rust/Rust.sublime-build from the list (enter rust build to filter the list quickly).

The results of that are this:

    "cmd": ["rustc", "$file"],
    "selector": "source.rust",
    "file_regex": "^(.*?):([0-9]+):([0-9]+):\\s[0-9]+:[0-9]+\\s(.*)$",
        "path": "/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin"

    "variants": [
            "selector": "source.rust",
            "cmd": ["./$file_base_name"],
            "name": "Run",
                "cmd": ["$file_base_name.exe"]

What @wbond was getting at above is that you should follow the directions at the link to create an override. That means you want to:

  1. Use Preferences/Browse Packages... from the menu to open the Packages folder
  2. Create a folder named Rust if one does not already exist
  3. Create a file inside of that folder named Rust.sublime-build with your modified contents

When you create those files/folders, make sure that you get the case correct.

When Sublime loads the Rust package, it’s going to get to the part of the sublime-package file that says that there is a file named Rust.sublime-build. Then it will notice that there’s a file in the Rust folder with that name and load that file instead of the one that’s inside of the sublime-package file, which overrides the file in the package with your version.

So in your case, you should move the file that you created to be in that folder by that name to have it take the place of the existing one. Depending on what you used in your own build file you may or may not want to copy the contents above into your own and modify it as needed, in case you didn’t have a file_regex or what have you.

Note also that the build above has a special osx key that gives the build a specific path to use on that platform; you can create a similar key for your platform if it’s not osx to provide a similar path.

1 Like


@OdatNurd: You my friend are a legend!! :slight_smile:

This is exactly what I needed and the way you explained it totally makes sense. I actually just tried it and it works just fine. I changed the “osx” section to “linux” and added the env PATH.

Thank you so much for going out of your way and explaing this to me. This is just what I needed!

(I switch between different projects and languages a lot, so having the language/build system autodetected is worth a lot to me!)

I will mark this as fixed!



@code Glad to hear you found a solution, and sorry I wasn’t able to help more earlier. I don’t know why your ~/.bash_profile is not being run correctly.

This article goes into a bit more detail for how it fits together on Mac OS.

Unfortunately, it seems that Mac OS has its own rules that is separate from Linux. (I’m on Linux and thus won’t be able to test.) On a Linux machine, your ~/.bash_profile should work.

All of this is assuming you are using bash as your login shell. I personally use zsh, so I would need to modify ~/.zprofile instead (on Linux; again here Mac OS may or may not have different conventions). If you’re using fish as your login shell, you’d need to follow the convention for fish, etc.

Upon further investigation, it seems that for Mac OS, programs do not automatically inherit the PATH from the login shell (!!!). I just remembered this because I recall Emacs has similar problems.

This answer will help you set the path that is visible to applications (e.g. Sublime Text and Emacs). In my opinion, this is the “proper” solution.




Actually the macOS version of Sublime works just fine.
The problems I’m having are all LINUX based. I created a .bash_profile and had it export the PATH to the .cargo/bin directory, but it is being completely ignored by Sublime. That’s why it cannot find rustc.



For anyone coming in, this worked for me. and I am using multiple different versions of python. I havent tested which one it uses (pretty sure the current active one in pyenv) but it works.

if [ -f ~/.zshrc ]; then
    . ~/.zshrc


Im glad I didnt have to change any other sublime setting tbh, I dont want to sync up yet another folder of sublime settings or package onto another machine everytime I set up a new env.
…and unfortunately with every new client that only accepts code from a specific device in their network I do have to set up a new env quite frequently.

Id rather edit the lowest point in my user config files and let all the apps use that rather than set up each apps configs individually.



The issue is one I’ve run across frequently. The problem is that the GUI (Gnome, KDE, etc.) is equivalent to a login shell. In the olden days you logged in on a terminal and that was your environment. Now the GUI performs a login. The shells you run in the terminals have their own environment. X is the underlying graphical environment so you want to modify the environment of your X session. For my Ubuntu the display manager/X session manager reads ~/.profile when you log in. This will also be used by bash when bash is run as a login shell only. I’ve gotten in the habit of setting my path in ~/.profile then putting anything else in the appropriate .zshrc or .bashrc file. The *rc files are read when the shell is interactive. This will make the path available to all apps run in your X session (including Sublime no matter how it’s launched) and includes your shells running in a Terminal.

I know it’s an older thread but this does answer your question of why it’s not working when you modify .bash_profile.



I faced nearly the same problem trying to setup GoGuru and other packages for golang development. I’m using Mac and /bin/zsh and any changes to .bash_profile and .bashrc had no effect for sublime text.

Finally, I’ve found this package which allows to execute shell script from env_file which sets environment variable. I think this may be the third way to solve your problem



That shouldn’t be necessary in recent versions unless you have a very slow bashrc, or don’t have zsh set as your login shell. A copy of your console output would help diagnose.



I also have a very similar problem, in my case I do not get any output error from the ST3 console. In the console I get
Running pandoc …
with the whole command I set in my build system. In the build console I don’t get any error, just a print of the varibles…I have absolutely no idea how to solve this issue

I made a post about it