How to run code in the sublime text?

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.

Run:execute Apex using OpenCTI in S...

Related:

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,

  1. Go to Sublime Text and open the required folder.
  1. 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.
Setting up Sublime text for code compile
  1. 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.
Build system Sublime text for your programming language

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.

  1. 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.
  1. Open up the console, and it will show you how long it took.
Write your code in sublime text
  1. 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.

  1. 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.
  2. 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.
Add compiler path
  1. It will bring it up. And then what you need to do is go to your path, press edit.
update path parameter for your programming in windows
  1. 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.
update path parameter for your programming in windows
  1. 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.
  1. 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 sublime text

New build system

  1. Save this file.
  2. 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.

image 26 - How to run code in the sublime text?

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.

  1. You need to type ‘cmd’, the first kind of key inside the JSON or dictionary, etc.
  1. 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.
image 27 - How to run code in the sublime text?
  1. 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.
image 28 - How to run code in the sublime text?
  1. Put a forward slash as explained with the name of the drive.
image 29 - How to run code in the sublime text?
  1. Add the following for the selector to choose it automatically.
image 30 - How to run code in the sublime text?
  1. You may see a new build system by clicking the build system option.
image 31 - How to run code in the sublime text?

So this is how you can change this executed code to run your code in sublime.

Final Verdict

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.