Settings > Permalinks has a form for this. In a setup script I want it as a line of code.
wp rewrite structure '/%postname%/'
The argument is the same pattern you’d type in the custom structure field: tags like %year%, %monthnum%, %category% and %postname%. The single quotes stop the shell from touching the percent signs. --category-base=topics and --tag-base=labels change the /category/ and /tag/ parts of archive URLs.
On Apache, add --hard so the rules in .htaccess get written too. Nginx ignores that file, it only needs the usual try_files line that sends everything to index.php.
To see what you have now:
wp option get permalink_structure
An empty answer means plain links like ?p=123.
Changing the structure on a site that is already live changes every post URL. Links from other sites, bookmarks and search results point to the old addresses. WordPress can guess its way to some of them, but I would not count on it. Test a few old links afterwards, and add redirects where they fail.
Further reading: wp rewrite structure, Using permalinks