There are several methods to run code in sublime. You can use the text editor, make changes in your settings, and build a new file written in the text you need or press some simple keys.
There might be a need to fix a path in the environment variables if you use C or C++, or Java. If you are using Python, Sublime Text is best for you, but you need to check your version and compare it to sublime text’s version.
How to run code in sublime Text
The steps mentioned here apply to all kinds of languages you are using.
In the sublime text, we have something called ‘Build System’, and we perform a build, and a build is just executing your code. So the way you can see all the stuff is,
- Go to Sublime Text and open the required folder.
- Go to Tools, and as you can see, we have a ‘build system’, we have ‘build’, and we have ‘build with’ along with ‘build results’ and ‘save all on build’. So this all is related to running your code.
- Hit the ‘Build System’, and you will see that we have an ‘automatic checker’ in Build System. If you don’t have an automatic checker, you should check that.
But you can see all of the built-in built systems that the sublime text has.
So if you are using any of these languages here and have the correct interpreter or compiler already installed on your system and that’s available on your system path, then these build paths or build systems should work just fine.
- Now you can run your code by pressing the control key ‘Ctrl’ and ‘b’ keys on your keyboard or the command ‘b’. Or you can press the F7 key or function F7, and F7 will run your code if you are on Mac or Linux.
- Open up the console, and it will show you how long it took.
- To close this window, you press the escape key ‘Esc’.
Adding System Path for Sublime Text
For some reason, if it doesn’t work for you, then you do a few different things to fix this.
- First of all, if you are using something like Python when you install Python, or if you reinstall Python, make sure you add it to your system path.
- You can access the system path on windows by going to your environment variables. So type in environment variables or ‘env’ in the windows search bar.
- It will bring it up. And then what you need to do is go to your path, press edit.
- Add the direct path to where your interpreter, compiler, etc., maybe. In this case, you can see that Python 3.8 is on my path. That means I can type the command Python and run the Python executable.
- If you don’t have it added to your system path, you can press new and then type in the actual path where the executable file is.
- If you don’t want to do that, another way is to create a new build system. Go to tools in Sublime text and then go to build system and new build system.
New build system
- Save this file.
- It will bring you to the user directory.
In the user directory, don’t change the directory when you save this file. And you want to call this file (name of the built). Sublime-built.
If you don’t have this extension, it will not show up as a potential build system.
Then make the changes described below to help you execute some code.
- You need to type ‘cmd’, the first kind of key inside the JSON or dictionary, etc.
- Then make a list, put the name of the command you want to run, and then put the file you want to run. ($file stands for run the current file). Press OK. Now run the build system in the terminal.
- You may also need to add a direct path to run the code for the interpreter. Go to the file you want it to access and copy this path to do this.
- Put a forward slash as explained with the name of the drive.
- Add the following for the selector to choose it automatically.
- You may see a new build system by clicking the build system option.
So this is how you can change this executed code to run your code in sublime.
All in all, these are the basic steps to run code in sublime. You have to have a sublime text editor and make changes if required. Just follow some above-mentioned steps to get your job done. Use whatever method you think is suitable for you.