Cannot view output of Serial.println() inside setup() routine

I have searched for "Arduino hello world" projects and they all write to serial in the setup() routine like this:

void setup() {
  Serial.begin(9600);
  Serial.println("Hello World!");
}

(for example on arduinogetstarted.com or instructables.com)

The problem is that when uploading, the serial window in the arduino IDE gets closed.
So you will never see the "Hello World!".

I received my Arduino today so everything is new to me.

But I wonder how this hello world ever worked?

does it have CH340 as USB chip? CH340 has some start delay. try to add delay(500); after Serial.begin

Juraj:
does it have CH340 as USB chip? CH340 has some start delay. try to add delay(500); after Serial.begin

It's a Arduino micro. I have debian linux.

I've read, that the programmer needs the serial window so it closes when you upload.

smorra:
I've read, that the programmer needs the serial window so it closes when you upload.

To be more accurate, it needs the serial port. Any time you re-open the serial window, it should reset the Arduino, and the program will run again from the beginning. Then you will see, "Hello World".

Some programs have

while (!Serial);

at the beginning to wait for the USB serial to come on line.

smorra:
It's a Arduino micro. I have debian linux.

I've read, that the programmer needs the serial window so it closes when you upload.

on Micro the MCU has native USB. to wait until it builds the connection you have to add
while (!Serial);

don't forget to remove it if you want to run a sketch without USB connection