Skip to content

Commit b900ce8

Browse files
committed
Massively simplify getting started with Scala
1 parent 7ec2ca6 commit b900ce8

File tree

2 files changed

+34
-102
lines changed

2 files changed

+34
-102
lines changed

_data/setup-scala.yml

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
1-
linux-x86-64: curl -fL https://github.com/coursier/coursier/releases/latest/download/cs-x86_64-pc-linux.gz | gzip -d > cs && chmod +x cs && ./cs setup
2-
linux-arm64: curl -fL https://github.com/VirtusLab/coursier-m1/releases/latest/download/cs-aarch64-pc-linux.gz | gzip -d > cs && chmod +x cs && ./cs setup
3-
macOS-x86-64: curl -fL https://github.com/coursier/coursier/releases/latest/download/cs-x86_64-apple-darwin.gz | gzip -d > cs && chmod +x cs && (xattr -d com.apple.quarantine cs || true) && ./cs setup
4-
macOS-arm64: curl -fL https://github.com/VirtusLab/coursier-m1/releases/latest/download/cs-aarch64-apple-darwin.gz | gzip -d > cs && chmod +x cs && (xattr -d com.apple.quarantine cs || true) && ./cs setup
5-
macOS-brew: brew install coursier && coursier setup
6-
windows-link: https://github.com/coursier/coursier/releases/latest/download/cs-x86_64-pc-win32.zip
1+
macos-linux-cli: curl https://raw.githubusercontent.com/VirtusLab/scala-cli/refs/heads/main/scala-cli.sh > scala && chmod +x scala
2+
windows-cli: Invoke-WebRequest "https://raw.githubusercontent.com/VirtusLab/scala-cli/refs/heads/main/scala-cli.bat" -OutFile "scala.bat”

_overviews/getting-started/install-scala.md

+32-96
Original file line numberDiff line numberDiff line change
@@ -33,48 +33,25 @@ The instructions below cover both Scala 2 and Scala 3.
3333

3434
{% include inner-documentation-sections.html links=page.newcomer_resources %}
3535

36-
## Install Scala on your computer
36+
## Install the Scala CLI
3737

38-
Installing Scala means installing various command-line tools such as the Scala compiler and build tools.
39-
We recommend using the Scala installer tool "Coursier" that automatically installs all the requirements, but you can still manually install each tool.
38+
### Install Scala in your project
4039

41-
### Using the Scala Installer (recommended way)
42-
43-
The Scala installer is a tool named [Coursier](https://get-coursier.io/docs/cli-overview), whose main command is named `cs`.
44-
It ensures that a JVM and standard Scala tools are installed on your system.
45-
Install it on your system with the following instructions.
40+
Download the Scala CLI launcher in your project directory:
4641

4742
<!-- Display tabs for each OS -->
4843
{% tabs install-cs-setup-tabs class=platform-os-options %}
4944

50-
<!-- macOS -->
51-
{% tab macOS for=install-cs-setup-tabs %}
45+
<!-- macOS/Linux -->
46+
{% tab macOS/Linux for=install-cs-setup-tabs %}
5247
Run the following command in your terminal, following the on-screen instructions:
53-
{% include code-snippet.html language='bash' codeSnippet=site.data.setup-scala.macOS-brew %}
54-
{% altDetails cs-setup-macos-nobrew "Alternatively, if you don't use Homebrew:" %}
55-
On the Apple Silicon (M1, M2, …) architecture:
56-
{% include code-snippet.html language='bash' codeSnippet=site.data.setup-scala.macOS-arm64 %}
57-
Otherwise, on the x86-64 architecture:
58-
{% include code-snippet.html language='bash' codeSnippet=site.data.setup-scala.macOS-x86-64 %}
59-
{% endaltDetails %}
60-
{% endtab %}
61-
<!-- end macOS -->
62-
63-
<!-- Linux -->
64-
{% tab Linux for=install-cs-setup-tabs %}
65-
Run the following command in your terminal, following the on-screen instructions.
66-
67-
On the x86-64 architecture:
68-
{% include code-snippet.html language='bash' codeSnippet=site.data.setup-scala.linux-x86-64 %}
69-
Otherwise, on the ARM64 architecture:
70-
{% include code-snippet.html language='bash' codeSnippet=site.data.setup-scala.linux-arm64 %}
48+
{% include code-snippet.html language='bash' codeSnippet=site.data.setup-scala.macos-linux-cli %}
7149
{% endtab %}
72-
<!-- end Linux -->
50+
<!-- end macOS/Linux -->
7351

7452
<!-- Windows -->
7553
{% tab Windows for=install-cs-setup-tabs %}
76-
Download and execute [the Scala installer for Windows]({{site.data.setup-scala.windows-link}})
77-
based on Coursier, and follow the on-screen instructions.
54+
{% include code-snippet.html language='bash' codeSnippet=site.data.setup-scala.windows-cli %}
7855
{% endtab %}
7956
<!-- end Windows -->
8057

@@ -83,71 +60,30 @@ Run the following command in your terminal, following the on-screen instructions
8360
<noscript>
8461
<p><span style="font-style:italic;">JavaScript is disabled, click the tab relevant for your OS.</span></p>
8562
</noscript>
86-
Follow the documentation from Coursier on
87-
[how to install and run `cs setup`](https://get-coursier.io/docs/cli-installation).
63+
Follow the documentation from the Scala CLI on
64+
[how to install and run `scala`](https://scala-cli.virtuslab.org/install).
8865
{% endtab %}
8966
<!-- end Other -->
9067

9168
{% endtabs %}
9269
<!-- End tabs -->
9370

94-
> <i class="fa fa-info"></i>&nbsp;&nbsp; You may need to restart your terminal, log out,
95-
> or reboot in order for the changes to take effect.
96-
{: .help-info}
97-
98-
<!-- Alternative Detail - test the `scala` command -->
99-
{% altDetails testing-your-setup 'Testing your setup' %}
100-
Check your setup with the command `scala -version`, which should output:
101-
```bash
102-
$ scala -version
103-
Scala code runner version: 1.4.3
104-
Scala version (default): {{site.scala-3-version}}
105-
```
106-
{% endaltDetails %}
107-
<!-- end Alternative Detail -->
108-
109-
110-
Along with managing JVMs, `cs setup` also installs useful command-line tools:
111-
112-
| Commands | Description |
113-
|----------|-------------|
114-
| `scalac` | the Scala compiler |
115-
| `scala`, `scala-cli` | [Scala CLI](https://scala-cli.virtuslab.org), interactive toolkit for Scala |
116-
| `sbt`, `sbtn` | The [sbt](https://www.scala-sbt.org/) build tool |
117-
| `amm` | [Ammonite](https://ammonite.io/) is an enhanced REPL |
118-
| `scalafmt` | [Scalafmt](https://scalameta.org/scalafmt/) is the Scala code formatter |
119-
120-
For more information about `cs`, read
121-
[coursier-cli documentation](https://get-coursier.io/docs/cli-overview).
122-
123-
> `cs setup` installs the Scala 3 compiler and runner by default (the `scalac` and
124-
> `scala` commands, respectively). Whether you intend to use Scala 2 or 3,
125-
> this is usually not an issue because most projects use a build tool that will
126-
> use the correct version of Scala irrespective of the one installed "globally".
127-
> Nevertheless, you can always launch a specific version of Scala using
128-
> ```
129-
> $ cs launch scala:{{ site.scala-version }}
130-
> $ cs launch scalac:{{ site.scala-version }}
131-
> ```
132-
> If you prefer Scala 2 to be run by default, you can force that version to be installed with:
133-
> ```
134-
> $ cs install scala:{{ site.scala-version }} scalac:{{ site.scala-version }}
135-
> ```
136-
137-
### ...or manually
138-
139-
You only need two tools to compile, run, test, and package a Scala project: Java 8 or 11,
140-
and Scala CLI.
141-
To install them manually:
142-
143-
1. if you don't have Java 8 or 11 installed, download
144-
Java from [Oracle Java 8](https://www.oracle.com/java/technologies/javase-jdk8-downloads.html), [Oracle Java 11](https://www.oracle.com/java/technologies/javase-jdk11-downloads.html),
145-
or [AdoptOpenJDK 8/11](https://adoptopenjdk.net/). Refer to [JDK Compatibility](/overviews/jdk-compatibility/overview.html) for Scala/Java compatibility detail.
146-
1. Install [Scala CLI](https://scala-cli.virtuslab.org/install)
71+
We recommend committing the scala executable together with your code so that
72+
everyone working on the project can compile and run the code without needing to install anything (not even Java).
73+
74+
### ...or/and install Scala on your computer
75+
76+
Follow the documentation from the Scala CLI on
77+
[how to install and run `scala`](https://scala-cli.virtuslab.org/install).
14778

14879
## Using the Scala CLI
14980

150-
In a directory of your choice, which we will call `<project-dir>`, create a file named `hello.scala` with the following code:
81+
This section assumes you downloaded the Scala CLI launcher in a directory of your choice, which we will call
82+
`<project-dir>`.
83+
If you installed the Scala CLI on your computer (globally) instead of in your `<project-dir>`, you should run the
84+
following commands with `scala` instead of `./scala`.
85+
86+
Create a file named `hello.scala` with the following code:
15187
```scala
15288
//> using scala {{site.scala-3-version}}
15389

@@ -161,10 +97,10 @@ the entry point in program execution. The method's type is `Unit`, which means i
16197
can be thought of as an analogue to the `void` keyword found in other languages. The `println` method will print the `"Hello, World!"`
16298
string to standard output.
16399

164-
To run the program, execute `scala run hello.scala` command from a terminal, within the `<project-dir>` directory. The file will be compiled and executed, with console output
100+
To run the program, execute `./scala run hello.scala` command from a terminal, within the `<project-dir>` directory. The file will be compiled and executed, with console output
165101
similar to following:
166102
```
167-
$ scala run hello.scala
103+
$ ./scala run hello.scala
168104
Compiling project (Scala {{site.scala-3-version}}, JVM (20))
169105
Compiled project (Scala {{site.scala-3-version}}, JVM (20))
170106
Hello, World!
@@ -187,7 +123,7 @@ the content of the `name` argument.
187123

188124
To pass the arguments when executing the program, put them after `--`:
189125
```
190-
$ scala run hello.scala -- Gabriel
126+
$ ./scala run hello.scala -- Gabriel
191127
Compiling project (Scala {{site.scala-3-version}}, JVM (20))
192128
Compiled project (Scala {{site.scala-3-version}}, JVM (20))
193129
Hello, Gabriel!
@@ -202,7 +138,7 @@ We use the [os-lib](https://github.com/com-lihaoyi/os-lib) library from the [Sca
202138
for that purpose. A dependency on the library can be added with the `//> using` directive. Put the following code in `counter.scala`.
203139
```scala
204140
//> using scala {{site.scala-3-version}}
205-
//> using dep "com.lihaoyi::os-lib:0.10.7"
141+
//> using dep "com.lihaoyi::os-lib:0.11.4"
206142

207143
@main
208144
def countFiles(): Unit =
@@ -216,7 +152,7 @@ sequence of paths.
216152

217153
Execute the program. The dependency will be automatically downloaded. The execution should result in a similar output:
218154
```
219-
$ scala run counter.scala
155+
$ ./scala run counter.scala
220156
Compiling project (Scala {{site.scala-3-version}}, JVM (20))
221157
Compiled project (Scala {{site.scala-3-version}}, JVM (20))
222158
4
@@ -241,16 +177,16 @@ This program is identical to the one above. However, other toolkit libraries wil
241177

242178
### Using the REPL
243179

244-
You can execute code interactively using the REPL provided by the `scala` command. Execute `scala` in the console without any arguments.
180+
You can execute code interactively using the REPL provided by the `scala` command. Execute `./scala` in the console without any arguments.
245181
```
246-
$ scala
182+
$ ./scala
247183
Welcome to Scala {{site.scala-3-version}} (20-ea, Java OpenJDK 64-Bit Server VM).
248184
Type in expressions for evaluation. Or try :help.
249185
250186
scala>
251187
```
252188

253-
Write a line of code to be executed and press enter.
189+
Write a line of code to be executed and press enter:
254190
```
255191
scala> println("Hello, World!")
256192
Hello, World!
@@ -266,7 +202,7 @@ val i: Int = 1
266202
scala>
267203
```
268204

269-
A new value of type `Int` has been created. If you provide an expression that can be evaluated, its result will be stored in an automatically created value.
205+
A new value of type `Int` has been created. If you provide an expression that can be evaluated, its result will be stored in an automatically created value:
270206
```
271207
scala> i + 3
272208
val res0: Int = 4

0 commit comments

Comments
 (0)