OCaml Remote Setup with Development Environment
This guide will detail the steps to set up a development environment in which your computer acts as a front end but all the meaningful work is done by computers on the CS network. This setup requires you to maintain a network connection with the Swarthmore CS network while you are working. You will require two tools: an SSH client and Microsoft’s Visual Studio Code, a lightweight, open-source development environment.
Setting Up OCaml
Since the CS network will be doing the computational work for us (compiling your code, running your programs, etc.), we need your CS account to be properly configured to compile and run OCaml programs. Use an SSH client to connect to the CS network. For most computers, this involves opening a command prompt or terminal and running the following command:
ssh username@cs.swarthmore.edu
Of course, you’ll need to replace username
with your own Swarthmore CS username. Once you’ve logged in, you’ll need to edit your ~/.bashrc
file to make use of the OCaml installation we’re using for this course. Using the command-line editor of your choice, open ~/.bashrc
. (If you’re not familiar with command-line editors, nano
is a simple one: run nano ~/.bashrc
.) Scroll to the bottom of the file and add these lines:
source /home/zpalmer/public/cs75/s22/environment.sh
Do not replace zpalmer
with your username. Save the file and exit. (In Nano, you can save by pressing Ctrl+O followed by enter; you can exit by pressing Ctrl+X.) If you’d like to see what this script is doing, you can cat
it.
Type exit
to close your connection to the CS network. Then, run ssh
again to reconnect. (This step is important as it allows us to test how your environment works with a fresh SSH connection.) Run the command which ocaml
. If it prints the message /home/zpalmer/public/cs75/s22/opam-root/4.13.1+flambda/bin/ocaml
, then you’re in good shape. Otherwise, please contact your instructor.
Configuring Visual Studio Code
Once we have OCaml set up on the CS network, we can configure your editor. Due to a bug in one of the plugins, it’s important that the above steps are completed before you proceed. As always, please contact your instructor if you have any trouble!
Installing and Configuring the SSH Extension
Once you’ve installed Visual Studio Code, you’ll need to install the SSH extension. This will allow Visual Studio Code to perform operations on the CS network over an SSH connection. First, click on the extensions button on the left side of the window.
The extension we need is Microsoft’s “Remote - SSH” extension. You can find it by searching for “SSH”, but make sure to install the plugin of this name provided by Microsoft. The other extensions do not provide the functionality we need.
Next, we need to tell Visual Studio Code how to connect to the CS network. Click on the Remote Explorer button on the left panel. Then, click on the small plus button at the top of the remote explorer to add a new remote configuration.
You will be asked to provide an SSH connection command. For this step, you should specify a CS network computer; do not just use cs.swarthmore.edu
. The SSH extension expects to be able to connect to the same computer each time; meanwhile, Swarthmore’s CS network will route you to a different computer each time you connect as a load-balancing measure. You should pick one of the following hosts:
butter.cs.swarthmore.edu
caper.cs.swarthmore.edu
cheese.cs.swarthmore.edu
oil.cs.swarthmore.edu
oregano.cs.swarthmore.edu
rosemary.cs.swarthmore.edu
Try to pick randomly – a six-sided die might be helpful – but remember to include your username. For instance, one might use the command ssh username@oregano.cs.swarthmore.edu
.
Press enter. You will be asked to choose an SSH configuration file. The first, default option is probably fine, so press enter again. Now you can press the small (often hidden) “Connect to Host in New Window” button to open an editor session using the SSH extension.
A new window will appear and you will be prompted for your CS network password. Provide it. You’ll observe a status report in the lower right of the new window as the editor performs a first-time setup. This might take a little while the first time, but it should be fast the next time you make this connection.
Installing OCaml Extensions
In this new window, open the Extensions tab again. It will look a little different this time, with extensions separated into “Local” and “SSH”. You probably won’t have any SSH extensions installed.
Search for and install three extensions. They are named exactly the following:
- “OCaml Platform” (for OCaml support in your editor)
- “OCaml Indentation” (for automatic code indentation)
- “Live Share” (for seamless collaborative editing that will be helpful later in the semester)
As you install plugins, they will appear in the SSH category; this is because they are being installed on the CS network and not on your local machine. This ensures, for instance, that the parts of the OCaml Platform extension that identify bugs are running on the same computer that the OCaml compiler is installed on. By the time you are finished, you should see all three extensions in your SSH category.
That’s It!
This development environment should be sufficient for your work in Compilers. It is helpful to note that terminals opened in the remote window (which can be opened in the edtior’s Terminal menu) will be opened on the remote machine, so you won’t need to keep a separate window open just to run commands. You will need to keep your connection to the Internet whle you work, though.
As always, please reach out if you have any difficulty configuring your development environment. A comfortable development environment is an important investment! Once you have a good environment, you’ll be able to focus much more productively on the interesting work.