How to run Intellij IDEA from terminal in detached mode
Asked Answered
L

7

10

I'm trying to run Intellij IDEA 2019.2 from terminal in Ubuntu 18.04.2 LTS with command idea.

But terminal is stayed connected to IDEA output - IDEA write logs to it.

I've tried to use &: idea &, but it didn't help - console is still connected to IDEA.

romach@romach:~/bin$ idea &
[2] 836
romach@romach:~/bin$ 2019-08-01 15:55:56,253 [   1189]   WARN - llij.ide.plugins.PluginManager - Docker integration not loaded: until build 182.SNAPSHOT < IU-192.5728.98 
2019-08-01 15:55:56,296 [   1232]   WARN - llij.ide.plugins.PluginManager - NodeJS not loaded: until build 191.SNAPSHOT < IU-192.5728.98 
2019-08-01 15:55:56,865 [   1801]   WARN - llij.ide.plugins.PluginManager - Docker integration not loaded: until build 182.SNAPSHOT < IU-192.5728.98 
2019-08-01 15:55:56,905 [   1841]   WARN - llij.ide.plugins.PluginManager - NodeJS not loaded: until build 191.SNAPSHOT < IU-192.5728.98 
2019-08-01 15:56:01,584 [   6520]   WARN - s.impl.EditorColorsManagerImpl - Cannot find scheme: VibrantInk from plugin: com.intellij.database
Lance answered 1/8, 2019 at 12:59 Comment(1)
Haha now I came in here looking for an answer because I think they default to detached now and I want regular.Anticoagulant
W
14

I don't think that idea is still "attached" to the console. It just uses the console as an output.
Try to use idea > /dev/null 2>&1 & to redirect the output to /dev/null

Waligore answered 1/8, 2019 at 16:22 Comment(3)
This won't prevent the main issue of closing the terminal also closes intellij ideBulimia
@Bulimia can't confirm. In my case PhpStorm (which is based on Intellij as far as i know) is kept open when redirecting the output as suggested by Feedward and closing the terminal afterwards.Reathareave
does not work with pycharm on ubuntu 22Caddis
M
12

Based on the @Feedforward, I added this lines to my ~/.bashrc file:

function idea() {
    /opt/idea-IC-202.6397.94/bin/idea.sh "$1" > /dev/null 2>&1 &
}

Note: replace the second line with the Idea proper path

With this function, you can open the current directory in Idea as follows:

$ idea .

Just replace "." with your desired directory

Mcnully answered 16/4, 2021 at 14:24 Comment(1)
finally a solution on a M1 macbook pro. The toolbox shell script simply wouldn't work for me on new install of OSX. although this is crude, it works. The other issue of course with this solution is that each time updating intellij one would need to update the path to the new toolbox installed intellij pathMetamorphosis
I
11

I was facing similar issue in MacOS, fixed it with below function defined in ~/.zshrc:

function idea() {
    open -a "IntelliJ IDEA" "$1"
}

Usage: idea ., idea README.md etc.

Intermittent answered 5/6, 2023 at 11:2 Comment(2)
Yeah this is definitely the simplest and most effective in my opinion. Very easy to modify, and add in whatever args as you want.Verulamium
Thanks a lot! This answer is exactly what I was looking for!Sixpenny
S
6

First, create the command-line launcher.

Tools > Create Command-line Launcher...

That will create /usr/local/bin/idea.

Now you can navigate to a project directory and open a project just like you'd be able to do with vscode.

$ cd ~/MyProject
$ idea .
$

IntelliJ IDEA will open the directory as a project. And your terminal will be ready for your next command.

But the trick to getting this to work is that IntelliJ IDEA must already be running.

If IntelliJ IDEA is not currently running, you'll see output printed to your terminal. Your terminal will not be available for additional commands until you close the project (unless you ran it as a background process).

If IntelliJ IDEA is currently running with just its Welcome screen, IntelliJ IDEA will open a new window and load the project.

If IntelliJ IDEA is currently running with one or more projects windows open, IntelliJ IDEA will prompt you for what to do:

Dialog asking where you'd like to open the project

In situations where you want the editor to wait, add the -w, --wait option.

To quickly edit a single file, add the -e option, which means LightEdit mode.

Splanchnology answered 7/8, 2021 at 20:40 Comment(0)
C
1

In my case, I had this problem with RubyMine, and basically the next solution works equally for all of the JetBrains products:

  1. Create the script:Tools > Create Command-line Launcher

  2. Add the next function to .zshrc (it's the same in bash):

    function rubymine() { ( mine "$@" & ) > /dev/null 2>&1 }

Replace rubymine with any other name that you prefer e.g.: intellij, and replace mine with your JetBrains product, e.g.: idea

It works better than the other mentioned solutions because this moves Rubymine to the background and suppress log messages.

Acknowledgments: makandracards

Conium answered 22/6, 2022 at 22:42 Comment(0)
M
0

So I'm in windows, and had the same question. The idea executable is a batch script in there, which is meant to be run attached to console, as its also the build system command (if you're into that stuff).

The Solution was to invoke the command idea64. Which is the actual binary that just launches the app. Linux should have similar behaviour, ideally. MacOS has a better way of getting at it, as @dds101010 mentions.

Macron answered 15/6, 2023 at 5:33 Comment(0)
R
0

In my case (Linux - Ubuntu) redirecting standard output to /dev/null and redirecting standard error to standard output using idea > /dev/null 2>&1 & didn't help to get the desired result, as it kept hanging the running program to the terminal.

I used nohup, which stands for 'no hang up'. It runs the command and makes it immune to hangups, so it will continue running after you close the terminal.

nohup idea ./projectA > /dev/null 2>&1 &

One can create a wrapper script that replaces the default idea command with the nohup version.

  1. Create the wrapper script:

    sudo nano /usr/local/bin/idea

  2. Add the following content to the script:

    #!/bin/bash
    
    if [ $# -eq 0 ]; then
        echo "Usage: webstorm <project-directory>"
        exit 1
    fi
    
    PROJECT_DIR=$1
    
    nohup /path/to/your/idea/bin/idea.sh "$PROJECT_DIR" > /dev/null 2>&1 &
  1. Make the script executable:

    sudo chmod +x /usr/local/bin/idea

  2. Open the project:

    idea /my-project-directory

*same applies to other JetBrains products, webstorm, goland, pycharm, and others.

Rod answered 9/7 at 16:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.