Is it possible to upgrade a 6 speed mountain bike to 7 or 8 speed?
Yes, you can upgrade your mountain bike.  However its a slippery slope of knock-on upgrades that can cost more than a nice, lightly-used bike.

For starters, you can't generally slap on a cassette or freewheel with more gears, because they're wider.

So the first thing to do is measure the "Over-Locknut Dimension", or OLD.  This is the horizontal distance between the locknuts on the hub, and is equal to the gap between the inside surfaces of the rear dropouts.

  This is measuring a rear hub that has no axle in the way.  This is 130mm

 This is measuring the rear dropouts using a ruler.  Lower tech but just as good.  This one is 126mm

If you have a steel bike frame, is slightly more options than an aluminium or carbon frame, because it can be cold-set (aka slightly widened at the rear dropouts) to fit a wider hub.  Can't do that with aluminium or carbon frames,

If you have a steel bike you can increase about one size, so 126mm to 130mm or 130mm to 135mm.  Then you have to align the rear dropouts again, using alignment tools like these half-axles showing minor tweak required. 



If you don't realign the dropouts, the wheel will wander easily, even hard pedal presses can pull the wheel out of alignment.



Once you have a wider hub, you can fit a wider cassette (don't bother buying a hub that takes a freewheel - that way lies bent axles and wallet-tears)

So you need a cassette, which will require a new chain.  Generally speaking 6/7/8 speed chains all use close to the same width, but you want an unworn chain to help prolong the life of your cassette.

Then check out the front chainrings for wear.  They wear slower than the cassette, but if the chain is making bad contact it could be time for new chainrings.

You will very likely need a new right-hand shifter too.  Your six-speed unit will have 6 indents/positions, and it won't handle the extra gears.  If you have a friction shifter it might work, or it might not.

While changing all this stuff you may as well install new cable inner wires and outer tubes too.  A cheap set costs about a happy meal.

Once that's all done, you need to reindex your gears, and might find that the 6 speed rear derailleur doesn't have enough range.  First try backing out the limit screws, but if you still can't get the chain to reach the biggest and smallest cogs then you're up for a new rear mech.

SUMMARY


Minimum


Hub
Cassette
Chain
Shifter
Wires

Maximum


Entire wheel
Rear derailleur mech
Chainring(s)



So yes its possible, but can be financially bad idea.  If you have spare parts from another bike, it becomes more cost-effective.