There isn’t a ton of info about starting out a new F# project under Linux so I’ve decided to document how I do it.
Following the instructions on the official F# site, install Mono and F#:
sudo apt-get install mono-complete fsharp
You can test that F# is installed by typing
to bring up the F# compiler.
Install Visual Studio Code
After installing VS Code press Ctr-Shift-X to open the Extension window and search for “Ionide” and install the following extensions:
Start a new project
Using Ctr-P bring up the command window and type:
Follow the instruction and select a class library project.
This will create the base project scaffolding including some files and folders. Now might be a good time to do a git init.
To build your project you must use the build.sh script. If you try this now, the command will fail because it won’t be able to find the Paket bootstrapper.
Paket is the package manager that downloads, installs and manages dependencies, much like NuGet, Cargo or RubyGem on other platforms.
So head on over and download the latest Paket bootstrapper specifically paket.bootstrapper.exe and drop it in the .paket folder that was created by Ionide.
You can now run
And Paket will create a paket.dependencies and paket.lock.
Adding some code to the project
There should be a folder with the project name you specified to Ionide . Let’s add a new file to this project.
You have two choices here:
- Add it manually
- Use Ionide to automatically add the file to the project
Add it manually
To add the file manually you must create a new file with a .fs extension using the file system or VS Code.
Next you must add your file to the project by editing the .fsproj file.
The alternative is to use Ionide a to add a new file for you.
Create the new .fs file like before, but this time use Ctr-P, type in
And select, Add current file to project. Voila!
Adding a new dependency to our existing project
Let’s add a new dependency to our project, MathNet.Numerics, a library that provides methods and algorithms for numerical computations.
Again let’s see how to add it both manually and using the Ionide plugin.
Before installing any packages make sure that the .paket/paket.exe file that was previously downloaded by the bootstrapper is executable. To do so, change the permissions via the command line or the GUI.
Add it manually
First open the paket.dependencies file in your project root and add the following line:
Open the .fsproj file of the project you want to add the dependency to, type in Ctr-P and then:
> paket: Add NuGet to current project
Debugging the project
Twice I’ve had the project refusing to build because of the paket dependencies after a Mono upgrade. In this case your best bet is to delete the dependency info in the fsproj and add them again.