Now that .NET 5 and C# are installed on our machines, we'll install dotnet script.
As mentioned in Welcome to C#, C# is a compiled language. In order to experiment with C#, we'll need a tool called a REPL, which stands for read-evaluate-print-loop. This allows us to run code a line at a time. This way we can practice, test, experiment, and have fun with C#.
We'll install and use a REPL called
We can install
dotnet script with the following terminal command:
$ dotnet tool install -g dotnet-script
Note that .NET 5 needs to be installed for this command to work. If you just installed .NET 5, restart the terminal. Otherwise, you will not be able to run
Next, configure your bash or zsh environment variables to find the location of
dotnet script. In the command line enter the following:
For bash users:
$ echo 'export PATH=$PATH:~/.dotnet/tools' >> ~/.bash_profile
For zsh users:
$ echo 'export PATH=$PATH:~/.dotnet/tools' >> ~/.zshrc
Now you can run the REPL! Enter
$ dotnet script in the command line and a prompt will open:
To try the REPL feature, enter:
> string hello = "hello world";
and then call the variable:
To exit the REPL press
Ctrl + C.
Lesson 3 of 5
Last updated October 12, 2021