Pathes for your mattermost at server:
/opt/ - path to folder with mattermost folder
A list of commands below:
cd /tmp
wget https://releases.mattermost.com/9.5.1/mattermost-team-9.5.1-linux-amd64.tar.gz
ls -- mattermost*.gz
tar -xf mattermost*.gz --transform='s,^[^/]+,\0-upgrade,'
sudo systemctl stop mattermost
cd /opt/
sudo find mattermost/ mattermost/client/ -mindepth 1 -maxdepth 1 ! ( -type d ( -path mattermost/client -o -path mattermost/client/plugins -o -path mattermost/config -o -path mattermost/logs -o -path mattermost/plugins -o -path mattermost/data ) -prune ) | sort | sudo xargs rm -r
sudo cp -an /tmp/mattermost-upgrade/. mattermost/
chown -R mattermost:mattermost mattermost
setcap cap_net_bind_service=+ep ./mattermost/bin/mattermost
sudo systemctl start mattermost
sudo rm -r /tmp/mattermost-upgrade/
sudo rm -i /tmp/mattermost*.gz