1

I am a beginner who just installed ubuntu 18.04 just fews days ago, and I am currently studying how to do everything from the terminal.

Chrome is a necessary application for me, for example, and I have already known how to run it by using the command line like/opt/google/chrome/chrome, which is the default path to chrome. But for Firefox, which was installed initially, I just need to type firefox and the browser works just fine.

And now I'm wondering if I can open Chrome in a similar way rather than typing the complicated path. Anyone has ideas?

Ruxu
  • 29

4 Answers4

4

TL;DR

For deb-packaged Google Chrome you can simply use google-chrome (or google-chrome-stable) command in the terminal.

Details

On my system I have stable version of Google Chrome 80 installed.
Its package name is google-chrome-stable, its binary files may be found by using

$ dpkg --listfiles google-chrome-stable | grep bin/
/usr/bin/google-chrome-stable

but really this file is a symlink to the location which you have mentioned (/opt/google/chrome/google-chrome):

$ ls -al /usr/bin/google-chrome-stable
lrwxrwxrwx 1 root root 32 Feb 13 07:04 /usr/bin/google-chrome-stable -> /opt/google/chrome/google-chrome

The /usr/bin is usually added to the PATH variable by default. So it is not really needed to add /opt/google/chrome/google-chrome to the PATH by hand.

For more complicated applications and their desktop- and executable files you can use methods from my other answer.

N0rbert
  • 103,263
4

There are different ways to customize the name by which you can launch an application:

Method 1 - Create an alias Next to all options given in the other answers, a convenient way to make it easier for you to start Chrome from the command line, and which does not require to be administrator, is to create an alias:

alias chrome=/opt/google/chrome/chrome

Add this command to your .bashrc file (already, some other aliases are defined there), so it is available anytime.

Method 2 - Create a symlink also does not require root permissions: you can create your personal bin folder in your home directory. There, create a symbolic link to the executable of Google Chrome as:

ln -s /usr/bin/google-chrome ~/bin/chrome

On Ubuntu, a local bin folder is automatically added to the PATH. After creating the bin folder, it will take only effect after your next log in.

Method 3 - Create a systemwide symlink If the change is to affect all users, create an appropriately named symlink in /usr/bin. As mentioned in the other answers, a symlink may already be available. If you prefer the shorter name chrome, feel free to create an additional symlink as

sudo ln -s /usr/bin/google-chrome /usr/bin/chrome

or rename the existing symlink.

Method 4 - Create a wrapper script. A simple executable bash script placed in your local bin folder or in urs/bin or another folder in your path would, for practical purposes, equally work. When executed, the script in turn calls the application by specifying its full pathway. A wrapper script is particularly suited if there is a need to customize the working environment prior to launching the application. Thus, the script could change the working directory, set or change environment variables, etc.

vanadium
  • 97,564
1

export PATH=$PATH:/opt/google/chrome/chrome

This will allow you to type chrome in your terminal to launch it.

This works by setting your path variable to itself and then appending :/opt/google/chrome/chrome

1

This is what the $PATH variable is for. When you're able to call firefox (or gedit, or whatever) by name, without referencing an absolute path, that's usually because it's in /usr/bin/ and /usr/bin/ is in your $PATH by default.

You can add an export statement to your .profile (so it's persistent) and reload it with:

echo 'export PATH=$PATH:/opt/google/chrome' >> ~/.profile
source ~/.profile

And then you can call Chrome with the simple chrome command in terminal. You can also go to Settings > Keyboard Shortcuts and set up a keyboard shortcut so you can open it without the terminal at all, or even set it as a startup application so it opens by default on login.

Lewis
  • 49