Not always. It is more complex.
There are neccessary occasions - ones that a person cannot reasonably avoid.
And there may be proportionate reasons to enter a known occasion of sin (eg a doctor entering a brothel to treat a sick person).
But in general - yes, there is an obligation to avoid known occasions of sins of grave matter. The application of such an obligation is best determined with one’s confessor.
Temptation alone does not define a near occasion of sin; it is defined by the likelihood to sin. But one should avoid unneccessary temptations too.
Loosely speaking, in common usage, “mortal sin” = “grave matter”.
The term “mortal sin” is used generally to decribe sins that are objectively mortal sins - ie sins of grave matter.
It is also a term used more specifically to describe personal mortal sin - ie sins of grave matter, with knowledge and consent.
We must also note that sins of grave matter that do not meet (for a given person) the requirements for personal mortal sin are absolutely to be avoided too. Their graveness is to be avoided, even if culpability is diminished. So, their occasion is to be avoided also.
You can read more about occasions of sin here: