Setting collection variables manually and then getting them was
always possible.
Setting collection variables in scripts and not just manually became
possible in version 7.9.0 which was released in October 2019.
As of writing this, there is still a lot of obsolete misinformation about it
out there - on the internet in general - but sadly also here at
stackoverflow.
Although joseluislopez87 has already correctly answered the question, I am
adding this answer in an attempt to help clear up any remaining confusion.
To find out who was right and who was wrong, I made a simple little experiment.
Below I describe what I did. I explain how you can replicate the exact same
experiment yourself.
I have created a Postman collection by the name ManipCollVars
(ManipulateCollectionVariables seemed a little too long).
You can download and save it to your local drive from:
https://schulze.000webhostapp.com/postman/variables/ManipCollVars.pm_coll.json.
Then - from your Postman desktop app (not the chrome extension) - import
ManipCollVars as shown in the figure below.
(The GET request is https://postman-echo.com/get.)

To see the initial value of the collection variable CollectionVar,
click on the three mini circles next to the collection name (tooltip:
View more actions). Then click Edit. See the figure below.

As in the figure below, click on the Variables tab.
Notice how the CURRENT VALUE of CollectionVar is
equal to Initial Value. Close the EDIT COLLECTION window.

Click on the request ManipCollVars-Request, and then on its Tests
tab as shown in the figure below.
Disregard the two tests and instead focus on lines 7-11:
// Will now try to change `CollectionVar` to some new value:
pm.collectionVariables.set('CollectionVar', 'Some New Value');
// Then print the new value of `CollectionVar` to the console:
console.log(pm.collectionVariables.get('CollectionVar'));
// ^^ Does `collVar` contain "Initial Value" or "Some New Value"?

Click on the blue Send button, and then open the Console in the
bottom left corner. See the figure below.
Notice how the value of the collection variable has changed from Initial Value to Some New Value. - Issue settled!

To double-check that the value has indeed changed, click once again on the
ellipsis (? ? ?) next to the name of the collection, on Edit,
and then on the Variables tab. See the figure below.
Notice how the CURRENT VALUE of CollectionVar is now
Some New Value. - Confirmed!

References: