How do I get the taxonomy term's path alias? I have come up with a need to show a node term's URL alias using plain php in drupal 8 but I can't figure out how to do it.
In my custom module, I want to get /fruits/apples in a variable upon loading a node which is linked with Fruits term.

Here you can see the Edit Term settings page in which I have set the URL alias of the term Fruits to /fruits/apples. I want to get this URL alias whenever a user loads a page linked to this term.
You can get it by this way as well (assuming you know $id in advance in code) as of Drupal 8.5.x:
1. For taxonomy term:
Term::load($id); //not important
$aliasManager = \Drupal::service('path.alias_manager');
$alias = $aliasManager-&gt;getAliasByPath('/taxonomy/term/'.$id);

2. For node:
$node = \Drupal::entityManager()-&gt;getStorage('node')-&gt;load($id); //not important
$aliasManager = \Drupal::service('path.alias_manager');
$alias = $aliasManager-&gt;getAliasByPath('/node/'.$id);

OUTPUT:
$alias = /fruits/apples
EDIT:
As of Drupal 8.8.x, path.alias_manager has been deprecated, use path_alias.manager in future versions of Drupal.